typescript-express-starter 10.0.0 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CONTRIBUTORS.md +8 -0
  2. package/lib/default/Makefile +1 -1
  3. package/lib/graphql/Makefile +1 -1
  4. package/lib/graphql/src/app.ts +2 -3
  5. package/lib/graphql/src/database/index.ts +23 -19
  6. package/lib/knex/Makefile +2 -2
  7. package/lib/knex/src/app.ts +3 -4
  8. package/lib/knex/src/database/index.ts +20 -17
  9. package/lib/mikro-orm/Makefile +2 -2
  10. package/lib/mikro-orm/src/app.ts +2 -1
  11. package/lib/mongoose/Makefile +2 -2
  12. package/lib/mongoose/src/app.ts +2 -7
  13. package/lib/mongoose/src/database/index.ts +17 -8
  14. package/lib/node-postgres/.env.development.local +7 -0
  15. package/lib/node-postgres/.env.production.local +7 -0
  16. package/lib/node-postgres/.env.test.local +7 -0
  17. package/lib/node-postgres/.swcrc +0 -1
  18. package/lib/node-postgres/Makefile +1 -1
  19. package/lib/node-postgres/src/app.ts +0 -6
  20. package/lib/node-postgres/src/config/index.ts +1 -1
  21. package/lib/node-postgres/src/database/index.ts +6 -2
  22. package/lib/node-postgres/src/database/init.sql +11 -108
  23. package/lib/node-postgres/src/middlewares/auth.middleware.ts +12 -4
  24. package/lib/node-postgres/src/routes/auth.route.ts +2 -2
  25. package/lib/node-postgres/src/routes/users.route.ts +2 -2
  26. package/lib/node-postgres/src/services/auth.service.ts +66 -15
  27. package/lib/node-postgres/src/services/users.service.ts +103 -21
  28. package/lib/node-postgres/src/test/auth.test.ts +8 -3
  29. package/lib/node-postgres/src/test/users.test.ts +16 -15
  30. package/lib/node-postgres/tsconfig.json +0 -1
  31. package/lib/prisma/Makefile +2 -2
  32. package/lib/prisma/src/routes/users.route.ts +1 -1
  33. package/lib/routing-controllers/Makefile +1 -1
  34. package/lib/sequelize/.sequelizerc +8 -0
  35. package/lib/sequelize/Makefile +2 -2
  36. package/lib/sequelize/package.json +3 -1
  37. package/lib/sequelize/src/app.ts +2 -2
  38. package/lib/sequelize/src/config/sequelize-cli.js +15 -0
  39. package/lib/typegoose/Makefile +2 -2
  40. package/lib/typegoose/src/app.ts +4 -8
  41. package/lib/typegoose/src/database/index.ts +12 -5
  42. package/lib/typeorm/.env.development.local +5 -5
  43. package/lib/typeorm/.env.production.local +5 -5
  44. package/lib/typeorm/.env.test.local +5 -5
  45. package/lib/typeorm/Makefile +1 -1
  46. package/lib/typeorm/docker-compose.yml +8 -8
  47. package/lib/typeorm/src/app.ts +2 -3
  48. package/lib/typeorm/src/config/index.ts +1 -1
  49. package/lib/typeorm/src/database/index.ts +23 -19
  50. package/lib/typeorm/src/test/auth.test.ts +1 -1
  51. package/lib/typeorm/src/test/users.test.ts +1 -1
  52. package/package.json +1 -1
  53. package/.vscode/configurationCache.log +0 -1
  54. package/.vscode/dryrun.log +0 -6
  55. package/.vscode/settings.json +0 -3
  56. package/.vscode/targets.log +0 -239
  57. package/lib/node-postgres/src/models/users.model.ts +0 -9
  58. /package/lib/default/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  59. /package/lib/graphql/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  60. /package/lib/knex/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  61. /package/lib/mikro-orm/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  62. /package/lib/mongoose/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  63. /package/lib/prisma/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  64. /package/lib/routing-controllers/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  65. /package/lib/sequelize/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  66. /package/lib/typegoose/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
  67. /package/lib/typeorm/src/exceptions/{httpException.ts → HttpException.ts} +0 -0
package/CONTRIBUTORS.md CHANGED
@@ -59,3 +59,11 @@
59
59
  - Markus Laubscher [https://github.com/markuslaubscher](https://github.com/markuslaubscher)
60
60
 
61
61
  - coder-palak [https://github.com/coder-palak](https://github.com/coder-palak)
62
+
63
+ - H2RO [https://github.com/primary-1](https://github.com/primary-1)
64
+
65
+ - Emmanuel Yeboah [https://github.com/noelzappy](https://github.com/noelzappy)
66
+
67
+ - Jonathan Felicity [https://github.com/jonathanfelicity](https://github.com/jonathanfelicity)
68
+
69
+ - Hichem Fantar [https://github.com/hichemfantar](https://github.com/hichemfantar)
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -8,7 +8,6 @@ import express from 'express';
8
8
  import helmet from 'helmet';
9
9
  import hpp from 'hpp';
10
10
  import { buildSchema } from 'type-graphql';
11
- import { createConnection } from 'typeorm';
12
11
  import { NODE_ENV, PORT, ORIGIN, CREDENTIALS } from '@config';
13
12
  import { dbConnection } from '@database';
14
13
  import { AuthMiddleware, AuthCheckerMiddleware } from '@middlewares/auth.middleware';
@@ -45,8 +44,8 @@ export class App {
45
44
  return this.app;
46
45
  }
47
46
 
48
- private connectToDatabase() {
49
- createConnection(dbConnection);
47
+ private async connectToDatabase() {
48
+ await dbConnection();
50
49
  }
51
50
 
52
51
  private initializeMiddlewares() {
@@ -1,22 +1,26 @@
1
1
  import { join } from 'path';
2
- import { ConnectionOptions } from 'typeorm';
2
+ import { createConnection, ConnectionOptions } from 'typeorm';
3
3
  import { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB } from '@config';
4
4
 
5
- export const dbConnection: ConnectionOptions = {
6
- type: 'postgres',
7
- username: POSTGRES_USER,
8
- password: POSTGRES_PASSWORD,
9
- host: POSTGRES_HOST,
10
- port: Number(POSTGRES_PORT),
11
- database: POSTGRES_DB,
12
- synchronize: true,
13
- logging: false,
14
- entities: [join(__dirname, '../**/*.entity{.ts,.js}')],
15
- migrations: [join(__dirname, '../**/*.migration{.ts,.js}')],
16
- subscribers: [join(__dirname, '../**/*.subscriber{.ts,.js}')],
17
- cli: {
18
- entitiesDir: 'src/entities',
19
- migrationsDir: 'src/migration',
20
- subscribersDir: 'src/subscriber',
21
- },
22
- };
5
+ export const dbConnection = async () => {
6
+ const dbConfig: ConnectionOptions = {
7
+ type: 'postgres',
8
+ username: POSTGRES_USER,
9
+ password: POSTGRES_PASSWORD,
10
+ host: POSTGRES_HOST,
11
+ port: Number(POSTGRES_PORT),
12
+ database: POSTGRES_DB,
13
+ synchronize: true,
14
+ logging: false,
15
+ entities: [join(__dirname, '../**/*.entity{.ts,.js}')],
16
+ migrations: [join(__dirname, '../**/*.migration{.ts,.js}')],
17
+ subscribers: [join(__dirname, '../**/*.subscriber{.ts,.js}')],
18
+ cli: {
19
+ entitiesDir: 'src/entities',
20
+ migrationsDir: 'src/migration',
21
+ subscribersDir: 'src/subscriber',
22
+ },
23
+ };
24
+
25
+ await createConnection(dbConfig);
26
+ }
package/lib/knex/Makefile CHANGED
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -43,4 +43,4 @@ remove: ## Remove the volumes
43
43
 
44
44
  #-- Database
45
45
  db: ## Start the local database MySQL
46
- docker-compose up -d mysql
46
+ docker-compose up -d mysql
@@ -6,11 +6,10 @@ import express from 'express';
6
6
  import helmet from 'helmet';
7
7
  import hpp from 'hpp';
8
8
  import morgan from 'morgan';
9
- import { Model } from 'objection';
10
9
  import swaggerJSDoc from 'swagger-jsdoc';
11
10
  import swaggerUi from 'swagger-ui-express';
12
11
  import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
13
- import { knex } from '@database';
12
+ import { dbConnection } from '@database';
14
13
  import { Routes } from '@interfaces/routes.interface';
15
14
  import { ErrorMiddleware } from '@middlewares/error.middleware';
16
15
  import { logger, stream } from '@utils/logger';
@@ -45,8 +44,8 @@ export class App {
45
44
  return this.app;
46
45
  }
47
46
 
48
- private connectToDatabase() {
49
- Model.knex(knex());
47
+ private async connectToDatabase() {
48
+ await dbConnection();
50
49
  }
51
50
 
52
51
  private initializeMiddlewares() {
@@ -1,21 +1,24 @@
1
+ import { Model } from 'objection';
1
2
  import Knex from 'knex';
2
3
  import { DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE } from '@config';
3
4
 
4
- const dbConnection = {
5
- client: 'mysql',
6
- connection: {
7
- charset: 'utf8',
8
- timezone: 'UTC',
9
- user: DB_USER,
10
- password: DB_PASSWORD,
11
- host: DB_HOST,
12
- port: DB_PORT,
13
- database: DB_DATABASE,
14
- },
15
- pool: {
16
- min: 2,
17
- max: 10,
18
- },
19
- };
5
+ export const dbConnection = async () => {
6
+ const dbConfig = {
7
+ client: 'mysql',
8
+ connection: {
9
+ charset: 'utf8',
10
+ timezone: 'UTC',
11
+ user: DB_USER,
12
+ password: DB_PASSWORD,
13
+ host: DB_HOST,
14
+ port: DB_PORT,
15
+ database: DB_DATABASE,
16
+ },
17
+ pool: {
18
+ min: 2,
19
+ max: 10,
20
+ },
21
+ };
20
22
 
21
- export const knex = () => Knex(dbConnection);
23
+ await Model.knex(Knex(dbConfig));
24
+ };
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -43,4 +43,4 @@ remove: ## Remove the volumes
43
43
 
44
44
  #-- Database
45
45
  db: ## Start the local database MongoDB
46
- docker-compose up -d mongo
46
+ docker-compose up -d mongo
@@ -53,8 +53,9 @@ export class App {
53
53
  DI.userRepository = DI.orm.em.getRepository(UserEntity);
54
54
  } catch (error) {
55
55
  logger.error(error);
56
+ } finally {
57
+ this.app.use((_1, _2, next) => RequestContext.create(DI.orm.em, next));
56
58
  }
57
- this.app.use((_1, _2, next) => RequestContext.create(DI.orm.em, next));
58
59
  }
59
60
 
60
61
  private initializeMiddlewares() {
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -43,4 +43,4 @@ remove: ## Remove the volumes
43
43
 
44
44
  #-- Database
45
45
  db: ## Start the local database MongoDB
46
- docker-compose up -d mongo
46
+ docker-compose up -d mongo
@@ -6,11 +6,10 @@ import express from 'express';
6
6
  import helmet from 'helmet';
7
7
  import hpp from 'hpp';
8
8
  import morgan from 'morgan';
9
- import { connect, set } from 'mongoose';
10
9
  import swaggerJSDoc from 'swagger-jsdoc';
11
10
  import swaggerUi from 'swagger-ui-express';
12
11
  import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
13
- import { dbConnection } from '@databases';
12
+ import { dbConnection } from '@database';
14
13
  import { Routes } from '@interfaces/routes.interface';
15
14
  import { ErrorMiddleware } from '@middlewares/error.middleware';
16
15
  import { logger, stream } from '@utils/logger';
@@ -46,11 +45,7 @@ export class App {
46
45
  }
47
46
 
48
47
  private async connectToDatabase() {
49
- if (this.env !== 'production') {
50
- set('debug', true);
51
- }
52
-
53
- await connect(dbConnection.url, dbConnection.options);
48
+ await dbConnection();
54
49
  }
55
50
 
56
51
  private initializeMiddlewares() {
@@ -1,9 +1,18 @@
1
- import { DB_HOST, DB_PORT, DB_DATABASE } from '@config';
1
+ import { connect, set } from 'mongoose';
2
+ import { NODE_ENV, DB_HOST, DB_PORT, DB_DATABASE } from '@config';
2
3
 
3
- export const dbConnection = {
4
- url: `mongodb://${DB_HOST}:${DB_PORT}/${DB_DATABASE}`,
5
- options: {
6
- useNewUrlParser: true,
7
- useUnifiedTopology: true
8
- },
9
- };
4
+ export const dbConnection = async () => {
5
+ const dbConfig = {
6
+ url: `mongodb://${DB_HOST}:${DB_PORT}/${DB_DATABASE}`,
7
+ options: {
8
+ useNewUrlParser: true,
9
+ useUnifiedTopology: true
10
+ },
11
+ };
12
+
13
+ if (NODE_ENV !== 'production') {
14
+ set('debug', true);
15
+ }
16
+
17
+ await connect(dbConfig.url, dbConfig.options);
18
+ }
@@ -11,3 +11,10 @@ LOG_DIR = ../logs
11
11
  # CORS
12
12
  ORIGIN = *
13
13
  CREDENTIALS = true
14
+
15
+ # DATABASE
16
+ POSTGRES_USER = root
17
+ POSTGRES_PASSWORD = password
18
+ POSTGRES_HOST = localhost
19
+ POSTGRES_PORT = 5432
20
+ POSTGRES_DB = dev
@@ -11,3 +11,10 @@ LOG_DIR = ../logs
11
11
  # CORS
12
12
  ORIGIN = your.domain.com
13
13
  CREDENTIALS = true
14
+
15
+ # DATABASE
16
+ POSTGRES_USER = root
17
+ POSTGRES_PASSWORD = password
18
+ POSTGRES_HOST = pg
19
+ POSTGRES_PORT = 5432
20
+ POSTGRES_DB = dev
@@ -11,3 +11,10 @@ LOG_DIR = ../logs
11
11
  # CORS
12
12
  ORIGIN = *
13
13
  CREDENTIALS = true
14
+
15
+ # DATABASE
16
+ POSTGRES_USER = root
17
+ POSTGRES_PASSWORD = password
18
+ POSTGRES_HOST = pg
19
+ POSTGRES_PORT = 5432
20
+ POSTGRES_DB = dev
@@ -28,7 +28,6 @@
28
28
  "@exceptions/*": ["exceptions/*"],
29
29
  "@interfaces/*": ["interfaces/*"],
30
30
  "@middlewares/*": ["middlewares/*"],
31
- "@models/*": ["models/*"],
32
31
  "@services/*": ["services/*"],
33
32
  "@utils/*": ["utils/*"]
34
33
  }
@@ -25,7 +25,7 @@ build: ## Build the container image - Production
25
25
  docker build -t ${APP_NAME}\
26
26
  -f Dockerfile.prod .
27
27
 
28
- build-dev: ## Build the container image - Dvelopment
28
+ build-dev: ## Build the container image - Development
29
29
  docker build -t ${APP_NAME}\
30
30
  -f Dockerfile.dev .
31
31
 
@@ -9,7 +9,6 @@ import morgan from 'morgan';
9
9
  import swaggerJSDoc from 'swagger-jsdoc';
10
10
  import swaggerUi from 'swagger-ui-express';
11
11
  import { NODE_ENV, PORT, LOG_FORMAT, ORIGIN, CREDENTIALS } from '@config';
12
- import { client } from '@database';
13
12
  import { Routes } from '@interfaces/routes.interface';
14
13
  import { ErrorMiddleware } from '@middlewares/error.middleware';
15
14
  import { logger, stream } from '@utils/logger';
@@ -24,7 +23,6 @@ export class App {
24
23
  this.env = NODE_ENV || 'development';
25
24
  this.port = PORT || 3000;
26
25
 
27
- this.connectToDatabase();
28
26
  this.initializeMiddlewares();
29
27
  this.initializeRoutes(routes);
30
28
  this.initializeSwagger();
@@ -44,10 +42,6 @@ export class App {
44
42
  return this.app;
45
43
  }
46
44
 
47
- private connectToDatabase() {
48
- client.connect();
49
- }
50
-
51
45
  private initializeMiddlewares() {
52
46
  this.app.use(morgan(LOG_FORMAT, { stream }));
53
47
  this.app.use(cors({ origin: ORIGIN, credentials: CREDENTIALS }));
@@ -3,4 +3,4 @@ config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
3
3
 
4
4
  export const CREDENTIALS = process.env.CREDENTIALS === 'true';
5
5
  export const { NODE_ENV, PORT, SECRET_KEY, LOG_FORMAT, LOG_DIR, ORIGIN } = process.env;
6
- export const { DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE } = process.env;
6
+ export const { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB } = process.env;
@@ -1,6 +1,10 @@
1
1
  import { Client } from 'pg';
2
- import { DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_DATABASE } from '@config';
2
+ import { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB } from '@config';
3
3
 
4
4
  export const client = new Client({
5
- connectionString: `postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}`,
5
+ connectionString: `postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}`,
6
6
  });
7
+
8
+ client.connect();
9
+
10
+ export default client;
@@ -1,110 +1,13 @@
1
- -- TABLE 존재할 경우 삭제
2
- DROP TABLE IF EXISTS teachers cascade;
3
- DROP TABLE IF EXISTS classes cascade;
4
- DROP TABLE IF EXISTS students cascade;
5
- DROP TABLE IF EXISTS classes_category cascade;
6
- DROP TABLE IF EXISTS enrolment cascade;
7
-
8
- -- ============
9
- -- 강사 테이블
10
- -- ============
11
- -- 강사 테이블 생성
12
- CREATE TABLE teachers(
13
- "teacherId" SERIAL PRIMARY KEY,
14
- -- 강사 ID
15
- "teacherName" VARCHAR(32) NOT NULL,
16
- -- 강사명
17
- "teacherAbout" VARCHAR(48) -- 강사 정보
18
- );
19
- -- 강사 데이터 생성
20
- INSERT INTO teachers(
21
- "teacherId",
22
- "teacherName",
23
- "teacherAbout"
24
- )
25
- VALUES (1, '조현영', '웹 개발 강사'),
26
- (2, '개복치개발자', '안드로이드 코틀린 강사'),
27
- (3, '이고잉', '생활코딩 운영진 겸 강사'),
28
- (4, '김태원', '파이썬 알고리즘 강사'),
29
- (5, '윤재성', 'Kotiln 기반 안드로이드 강사'),
30
- (6, '조훈', '쿠버네티스 강사'),
31
- (7, 'Rookiss', '얼리언 엔진 전문 강사'),
32
- (8, '유용한IT학습', 'SQLD 자격증 취득 강사'),
33
- (9, '김태민', '쿠버네티스 강사'),
34
- (10, '큰돌', '알고리즘 강사');
35
- SELECT SETVAL(
36
- '"teachers_teacherId_seq"',
37
- (
38
- SELECT max("teacherId")
39
- FROM teachers
40
- )
41
- );
42
- -- ===================
43
- -- 강의 카테고리 테이블
44
- -- ===================
45
- -- 강의 카테고리 테이블 생성
46
- CREATE TABLE classes_category(
47
- "categoryId" SERIAL PRIMARY KEY,
48
- -- 카테고리 ID
49
- "categoryName" VARCHAR(32) UNIQUE NOT NULL -- 카테고리 명
50
- );
51
- -- 강의 카테고리 데이터 생성
52
- INSERT INTO classes_category("categoryId", "categoryName")
53
- VALUES (1, '웹'),
54
- (2, '앱'),
55
- (3, '게임'),
56
- (4, '알고리즘'),
57
- (5, '인프라'),
58
- (6, '데이터베이스');
59
- SELECT SETVAL(
60
- '"classes_category_categoryId_seq"',
61
- (
62
- SELECT max("categoryId")
63
- FROM classes_category
64
- )
65
- );
66
- -- ============
67
- -- 강의 테이블
68
- -- ============
69
- -- 강의 테이블 생성
70
- CREATE TABLE classes(
71
- "classId" SERIAL PRIMARY KEY,
72
- -- 강의 ID
73
- "className" VARCHAR(32) UNIQUE NOT NULL,
74
- -- 강의명
75
- "classPrice" INTEGER NOT NULL DEFAULT 0,
76
- -- 가격
77
- "introduce" TEXT,
78
- -- 강의 소개
79
- "active" BOOLEAN NOT NULL DEFAULT false,
80
- -- 강의 활성화 (true: 공개, false, 비공개)
1
+ -- If Exists Table Drop
2
+ DROP TABLE IF EXISTS users cascade;
3
+ -- ================
4
+ -- TABLE [users]
5
+ -- ================
6
+ -- create users table
7
+ CREATE TABLE users(
8
+ "id" SERIAL PRIMARY KEY,
9
+ "email" VARCHAR(32) UNIQUE NOT NULL,
10
+ "password" VARCHAR(48) NOT NULL,
81
11
  "createdAt" TIMESTAMP WITHOUT TIME ZONE DEFAULT(NOW() AT TIME ZONE 'utc'),
82
- -- 강의 생성 일자
83
- "updatedAt" TIMESTAMP WITHOUT TIME ZONE,
84
- -- 강의 수정 일자
85
- "teacherId" INTEGER REFERENCES teachers("teacherId") ON DELETE CASCADE,
86
- -- 강사 ID
87
- "categoryId" INTEGER REFERENCES classes_category("categoryId") ON DELETE CASCADE -- 강사 ID
88
- );
89
- -- ==============
90
- -- 수강생 테이블
91
- -- ==============
92
- -- 수강생 테이블 생성
93
- CREATE TABLE students(
94
- "studentId" SERIAL PRIMARY KEY,
95
- -- 수강생 ID
96
- "email" VARCHAR(48) UNIQUE NOT NULL,
97
- -- 수강생 이메일
98
- "nickname" VARCHAR(32) NOT NULL -- 수강생 닉네임
99
- );
100
- -- ===============
101
- -- 수강신청 테이블
102
- -- ===============
103
- -- 수강신청 테이블 생성
104
- CREATE TABLE enrolment(
105
- "classId" INTEGER REFERENCES classes("classId") ON DELETE CASCADE,
106
- -- 강의 ID
107
- "studentId" INTEGER REFERENCES students("studentId") ON DELETE CASCADE,
108
- -- 수강생 ID
109
- "applicationAt" TIMESTAMP WITHOUT TIME ZONE DEFAULT(NOW() AT TIME ZONE 'utc') -- 신청 일자
12
+ "updatedAt" TIMESTAMP WITHOUT TIME ZONE
110
13
  );
@@ -1,9 +1,9 @@
1
1
  import { NextFunction, Response } from 'express';
2
2
  import { verify } from 'jsonwebtoken';
3
3
  import { SECRET_KEY } from '@config';
4
+ import pg from '@database';
4
5
  import { HttpException } from '@exceptions/httpException';
5
6
  import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
6
- import { UserModel } from '@models/users.model';
7
7
 
8
8
  const getAuthorization = req => {
9
9
  const coockie = req.cookies['Authorization'];
@@ -21,10 +21,18 @@ export const AuthMiddleware = async (req: RequestWithUser, res: Response, next:
21
21
 
22
22
  if (Authorization) {
23
23
  const { id } = (await verify(Authorization, SECRET_KEY)) as DataStoredInToken;
24
- const findUser = UserModel.find(user => user.id === id);
24
+ const { rows, rowCount } = await pg.query(`
25
+ SELECT
26
+ "email",
27
+ "password"
28
+ FROM
29
+ users
30
+ WHERE
31
+ "id" = $1
32
+ `, id);
25
33
 
26
- if (findUser) {
27
- req.user = findUser;
34
+ if (rowCount) {
35
+ req.user = rows[0];
28
36
  next();
29
37
  } else {
30
38
  next(new HttpException(401, 'Wrong authentication token'));
@@ -14,8 +14,8 @@ export class AuthRoute implements Routes {
14
14
  }
15
15
 
16
16
  private initializeRoutes() {
17
- this.router.post('/signup', ValidationMiddleware(CreateUserDto, 'body'), this.auth.signUp);
18
- this.router.post('/login', ValidationMiddleware(CreateUserDto, 'body'), this.auth.logIn);
17
+ this.router.post('/signup', ValidationMiddleware(CreateUserDto), this.auth.signUp);
18
+ this.router.post('/login', ValidationMiddleware(CreateUserDto), this.auth.logIn);
19
19
  this.router.post('/logout', AuthMiddleware, this.auth.logOut);
20
20
  }
21
21
  }
@@ -16,8 +16,8 @@ export class UserRoute implements Routes {
16
16
  private initializeRoutes() {
17
17
  this.router.get(`${this.path}`, this.user.getUsers);
18
18
  this.router.get(`${this.path}/:id(\\d+)`, this.user.getUserById);
19
- this.router.post(`${this.path}`, ValidationMiddleware(CreateUserDto, 'body'), this.user.createUser);
20
- this.router.put(`${this.path}/:id(\\d+)`, ValidationMiddleware(CreateUserDto, 'body', true), this.user.updateUser);
19
+ this.router.post(`${this.path}`, ValidationMiddleware(CreateUserDto), this.user.createUser);
20
+ this.router.put(`${this.path}/:id(\\d+)`, ValidationMiddleware(CreateUserDto, true), this.user.updateUser);
21
21
  this.router.delete(`${this.path}/:id(\\d+)`, this.user.deleteUser);
22
22
  }
23
23
  }