-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,394 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
"useTabs": false, | ||
"endOfLine": "lf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { configOptions } from './common/options'; | ||
import { ormOptions } from './common/ormconfig'; | ||
import { GraphQLWithUploadModule } from './graphql.module'; | ||
import { MyModule } from './modules/my/my.module'; | ||
|
||
const ENV = process.env.NODE_ENV; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ | ||
ConfigModule.forRoot(configOptions), | ||
TypeOrmModule.forRoot(ormOptions), | ||
GraphQLWithUploadModule.forRoot(), | ||
MyModule, | ||
], | ||
providers: [ | ||
{ | ||
provide: 'NODE_ENV', | ||
useValue: ENV, | ||
}, | ||
], | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { registerAs } from '@nestjs/config'; | ||
|
||
export const baseConfig = registerAs('base', () => ({ | ||
host: process.env.HOST, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Field, GraphQLISODateTime, ObjectType } from '@nestjs/graphql'; | ||
import { Exclude } from 'class-transformer'; | ||
import { | ||
BaseEntity, | ||
BeforeInsert, | ||
BeforeUpdate, | ||
Column, | ||
CreateDateColumn, | ||
DeleteDateColumn, | ||
Index, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
import { uuid } from './utils/uuid-transformer'; | ||
|
||
@ObjectType() | ||
export class CommonEntity extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
@Exclude() | ||
id: number; | ||
|
||
@Field(() => String, { description: 'uuid code' }) | ||
@Column({ name: 'code', type: 'varchar', length: 36 }) | ||
@Index({ unique: true }) | ||
code: string = uuid(); | ||
|
||
@Field(() => GraphQLISODateTime) | ||
@CreateDateColumn({ | ||
name: 'created_at', | ||
type: 'timestamp', | ||
}) | ||
createdAt: Date; | ||
|
||
@Field(() => GraphQLISODateTime) | ||
@UpdateDateColumn({ | ||
name: 'updated_at', | ||
type: 'timestamp', | ||
}) | ||
updatedAt: Date; | ||
|
||
@Field(() => GraphQLISODateTime, { nullable: true }) | ||
@DeleteDateColumn({ | ||
name: 'deleted_at', | ||
type: 'timestamp', | ||
default: null, | ||
nullable: true, | ||
}) | ||
deletedAt?: Date; | ||
|
||
@BeforeInsert() | ||
setCreatedAt() { | ||
if (!this.createdAt) { | ||
this.createdAt = new Date(); | ||
} | ||
} | ||
|
||
@BeforeUpdate() | ||
setUpdatedAt() { | ||
if (!this.updatedAt) { | ||
this.updatedAt = new Date(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { DataSource } from 'typeorm'; | ||
import { ormOptions } from './ormconfig'; | ||
|
||
export const dataSource: DataSource = new DataSource(ormOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface EnvVariables { | ||
NODE_ENV: string; | ||
SERVER_PORT: number; | ||
DB_URL: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ConfigModuleOptions } from '@nestjs/config'; | ||
import * as dotenv from 'dotenv'; | ||
import * as path from 'path'; | ||
import { baseConfig } from './baseconfig'; | ||
|
||
const ENV = process.env.NODE_ENV; | ||
dotenv.config({ | ||
path: path.join(__dirname, `../../config/.${ENV}.env`), | ||
}); | ||
|
||
export const configOptions: ConfigModuleOptions = { | ||
isGlobal: true, | ||
envFilePath: `config/.${ENV}.env`, | ||
load: [baseConfig], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as dotenv from 'dotenv'; | ||
import * as path from 'path'; | ||
import { My } from 'src/modules/my/entities/my.entity'; | ||
import { DataSourceOptions } from 'typeorm'; | ||
|
||
const ENV = process.env.NODE_ENV; | ||
dotenv.config({ | ||
path: path.join(__dirname, `../../config/.${ENV}.env`), | ||
}); | ||
|
||
export const ormOptions: DataSourceOptions = { | ||
type: 'mysql', | ||
url: process.env.DB_URL, | ||
logging: true, | ||
logger: 'file', | ||
synchronize: true, | ||
charset: 'utf8mb4', | ||
entities: [My], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
export const uuid = () => { | ||
const tokens = uuidv4().split('-'); | ||
return tokens[2] + tokens[1] + tokens[0] + tokens[3] + tokens[4]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; | ||
import { DynamicModule, Module } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config/dist/config.service'; | ||
import { GraphQLModule } from '@nestjs/graphql'; | ||
import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'; | ||
import path from 'path'; | ||
|
||
@Module({}) | ||
export class GraphQLWithUploadModule { | ||
static forRoot(): DynamicModule { | ||
return { | ||
module: GraphQLWithUploadModule, | ||
imports: [ | ||
GraphQLModule.forRootAsync<ApolloDriverConfig>({ | ||
inject: [ConfigService], | ||
driver: ApolloDriver, | ||
useFactory: async (configService: ConfigService) => ({ | ||
autoSchemaFile: path.join(process.cwd(), 'src/graphql/schema.gql'), | ||
driver: ApolloDriver, | ||
playground: false, | ||
plugins: | ||
configService.get('NODE_ENV') === 'dev' | ||
? [ApolloServerPluginLandingPageLocalDefault({ embed: true })] | ||
: undefined, | ||
context: ({ req, res, connection }) => { | ||
if (req) { | ||
const user = req.headers.authorization; | ||
return { ...req, ...res, user }; | ||
} else { | ||
return connection; | ||
} | ||
}, | ||
cors: { | ||
credentials: true, | ||
origin: [ | ||
'http://localhost:3000', | ||
'https://studio.apollographql.com', | ||
], | ||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', | ||
allowedHeaders: ['Content-Type', 'Authorization'], | ||
}, | ||
}), | ||
}), | ||
], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { GraphQLSchemaHost } from '@nestjs/graphql'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
await app.listen(3000); | ||
const app: INestApplication = await NestFactory.create(AppModule); | ||
const configService: ConfigService<unknown, boolean> = app.get(ConfigService); | ||
const port: number = configService.get<number>('SERVER_PORT'); | ||
app.get(GraphQLSchemaHost); | ||
|
||
await app.listen(port); | ||
} | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { InputType } from '@nestjs/graphql'; | ||
import { My } from '../entities/my.entity'; | ||
|
||
@InputType() | ||
export class CreateMyInput extends My {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { InputType, PartialType } from '@nestjs/graphql'; | ||
import { CreateMyInput } from './create-my.input'; | ||
|
||
@InputType() | ||
export class UpdateMyInput extends PartialType(CreateMyInput) {} |
Oops, something went wrong.