From 625d9933f81bea246d0b92e41b34d8ee908a4b59 Mon Sep 17 00:00:00 2001 From: JoonSoo-Kim Date: Tue, 21 Nov 2023 18:16:51 +0900 Subject: [PATCH 1/5] =?UTF-8?q?Fix:=20=EC=9C=A0=EC=A0=80=20DTO=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20Repository=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - createUser에서 email을 저장하지 않는 오류 수정 - email 정규표현식 오류 수정 --- BE/src/diaries/diaries.dto.ts | 2 +- BE/src/users/users.dto.ts | 4 +++- BE/src/users/users.repository.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/BE/src/diaries/diaries.dto.ts b/BE/src/diaries/diaries.dto.ts index 7a86f85..6cd5c32 100644 --- a/BE/src/diaries/diaries.dto.ts +++ b/BE/src/diaries/diaries.dto.ts @@ -8,7 +8,7 @@ export class CreateDiaryDto { content: string; @IsString() - @Matches(RegExp("^-?d+(.d+)?,-?d+(.d+)?,-?d+(.d+)?$"), { + @Matches(RegExp(/^-?d+(.d+)?,-?d+(.d+)?,-?d+(.d+)?$/), { message: "적절하지 않은 포인트 양식입니다", }) point: string; diff --git a/BE/src/users/users.dto.ts b/BE/src/users/users.dto.ts index 1e346f5..0d819d6 100644 --- a/BE/src/users/users.dto.ts +++ b/BE/src/users/users.dto.ts @@ -6,7 +6,9 @@ export class CreateUserDto { userId: string; @IsString() - @Matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$") + @Matches(RegExp(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/), { + message: "적절하지 않은 이메일 양식입니다.", + }) email: string; @IsString() diff --git a/BE/src/users/users.repository.ts b/BE/src/users/users.repository.ts index 5f8d1d9..448f067 100644 --- a/BE/src/users/users.repository.ts +++ b/BE/src/users/users.repository.ts @@ -9,11 +9,16 @@ import * as bcrypt from "bcryptjs"; export class UsersRepository { async createUser(createUserDto: CreateUserDto): Promise { - const { userId, password, nickname } = createUserDto; + const { userId, password, nickname, email } = createUserDto; const salt = await bcrypt.genSalt(); const hashedPassword = await bcrypt.hash(password, salt); - const user = User.create({ userId, password: hashedPassword, nickname }); + const user = User.create({ + userId, + password: hashedPassword, + nickname, + email, + }); try { await user.save(); From f8dac05199283e55cf212071513e59584369e126 Mon Sep 17 00:00:00 2001 From: JoonSoo-Kim Date: Tue, 21 Nov 2023 18:33:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EB=AA=A8=EC=96=91=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=9D=98=20user=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 모양 엔티티의 user의 타입을 Promise에서 User로 변경 - 엔티티 변경사항을 repository에 업데이트 --- BE/src/shapes/shapes.entity.ts | 2 +- BE/src/shapes/shapes.repository.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BE/src/shapes/shapes.entity.ts b/BE/src/shapes/shapes.entity.ts index 4898dbe..97408eb 100644 --- a/BE/src/shapes/shapes.entity.ts +++ b/BE/src/shapes/shapes.entity.ts @@ -20,7 +20,7 @@ export class Shape extends BaseEntity { uuid: string; @ManyToOne(() => User, (user) => user.userId, { nullable: false }) - user: Promise; + user: User; @Column() shapePath: string; diff --git a/BE/src/shapes/shapes.repository.ts b/BE/src/shapes/shapes.repository.ts index 95c72e9..883e70e 100644 --- a/BE/src/shapes/shapes.repository.ts +++ b/BE/src/shapes/shapes.repository.ts @@ -13,7 +13,7 @@ export class ShapesRepository { if (existingShape) return; - defaultShape.user = Promise.resolve(commonUser); + defaultShape.user = commonUser; const shape = Shape.create(defaultShape); await shape.save(); }), From b76fec32efe91855458bfec5d5f12b11d6d50127 Mon Sep 17 00:00:00 2001 From: JoonSoo-Kim Date: Tue, 21 Nov 2023 18:34:41 +0900 Subject: [PATCH 3/5] =?UTF-8?q?style:=20typeorm.config.ts=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - typeorm.config.ts파일에 있던 typeORMTestConfig를 typeorm.test.config.ts 파일을 생성하여 이동 --- BE/src/configs/typeorm.config.ts | 12 ------------ BE/src/configs/typeorm.test.config.ts | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 BE/src/configs/typeorm.test.config.ts diff --git a/BE/src/configs/typeorm.config.ts b/BE/src/configs/typeorm.config.ts index 9412a77..1a5c037 100644 --- a/BE/src/configs/typeorm.config.ts +++ b/BE/src/configs/typeorm.config.ts @@ -12,15 +12,3 @@ export const typeORMConfig: TypeOrmModuleOptions = { synchronize: false, timezone: "+09:00", }; - -export const typeORMTestConfig: TypeOrmModuleOptions = { - type: "mysql", - host: process.env.DB_HOST, - port: 3306, - username: process.env.DB_USER, - password: process.env.DB_PASS, - database: process.env.TEST_DB_NAME, - entities: ["src/**/*.entity{.ts,.js}"], - synchronize: true, - timezone: "+09:00", -}; diff --git a/BE/src/configs/typeorm.test.config.ts b/BE/src/configs/typeorm.test.config.ts new file mode 100644 index 0000000..896bede --- /dev/null +++ b/BE/src/configs/typeorm.test.config.ts @@ -0,0 +1,14 @@ +import "dotenv/config"; +import { TypeOrmModuleOptions } from "@nestjs/typeorm"; + +export const typeORMTestConfig: TypeOrmModuleOptions = { + type: "mysql", + host: process.env.DB_HOST, + port: 3306, + username: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.TEST_DB_NAME, + entities: ["src/**/*.entity{.ts,.js}"], + synchronize: true, + timezone: "+09:00", +}; From 1bb072a8befb3e25348f80e86a7062dd586e4658 Mon Sep 17 00:00:00 2001 From: JoonSoo-Kim Date: Tue, 21 Nov 2023 18:35:35 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20TypeormConfig=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - app.module에서 실행 환경에 따라 typeORMConfig와 typeORMTestConfig 를 골라 실행하도록 변경 --- BE/src/app.module.ts | 6 +++++- BE/test/app.e2e-spec.ts | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BE/src/app.module.ts b/BE/src/app.module.ts index fbbc3fe..65cdb97 100644 --- a/BE/src/app.module.ts +++ b/BE/src/app.module.ts @@ -1,3 +1,4 @@ +import "dotenv/config"; import { Module } from "@nestjs/common"; import { TypeOrmModule } from "@nestjs/typeorm"; import { typeORMConfig } from "./configs/typeorm.config"; @@ -8,10 +9,13 @@ import { IntroduceModule } from "./introduce/introduce.module"; import { ShapesModule } from "./shapes/shapes.module"; import { ShapesRepository } from "./shapes/shapes.repository"; import { UsersRepository } from "./users/users.repository"; +import { typeORMTestConfig } from "./configs/typeorm.test.config"; @Module({ imports: [ - TypeOrmModule.forRoot(typeORMConfig), + TypeOrmModule.forRoot( + process.env.NODE_ENV === "test" ? typeORMTestConfig : typeORMConfig, + ), UsersModule, DiariesModule, AuthModule, diff --git a/BE/test/app.e2e-spec.ts b/BE/test/app.e2e-spec.ts index fd5d51a..b64a1b9 100644 --- a/BE/test/app.e2e-spec.ts +++ b/BE/test/app.e2e-spec.ts @@ -2,15 +2,13 @@ import { Test, TestingModule } from "@nestjs/testing"; import { INestApplication } from "@nestjs/common"; import * as request from "supertest"; import { AppModule } from "../src/app.module"; -import { TypeOrmModule } from "@nestjs/typeorm"; -import { typeORMTestConfig } from "src/configs/typeorm.config"; describe("AppController (e2e)", () => { let app: INestApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [TypeOrmModule.forRoot(typeORMTestConfig), AppModule], + imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); From e995e29d94dacbd6c03fda10191f57c82e780ed4 Mon Sep 17 00:00:00 2001 From: JoonSoo-Kim Date: Tue, 21 Nov 2023 18:56:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20cross-env=EB=A5=BC=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20NODE=5FENV=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cross-env 설치 - NODE_ENV를 실행 환경마다 다르게 설정 --- BE/package-lock.json | 21 ++++++++++++++++++++- BE/package.json | 11 ++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/BE/package-lock.json b/BE/package-lock.json index 8a39427..80e3941 100644 --- a/BE/package-lock.json +++ b/BE/package-lock.json @@ -18,9 +18,9 @@ "@nestjs/typeorm": "^10.0.0", "@types/dotenv": "^8.2.0", "@types/passport-jwt": "^3.0.13", + "aws-sdk": "^2.1499.0", "bcryptjs": "^2.4.3", "class-transformer": "^0.5.1", - "aws-sdk": "^2.1499.0", "class-validator": "^0.14.0", "dotenv": "^16.3.1", "mysql2": "^3.6.3", @@ -40,6 +40,7 @@ "@types/supertest": "^2.0.12", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", + "cross-env": "^7.0.3", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", @@ -3758,6 +3759,24 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "devOptional": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/BE/package.json b/BE/package.json index 4daffd2..6cc3a27 100644 --- a/BE/package.json +++ b/BE/package.json @@ -8,16 +8,16 @@ "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", - "start": "nest start", - "start:dev": "nest start --watch", + "start": "cross-env NODE_ENV=production nest start", + "start:dev": "cross-env NODE_ENV=dev nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "jest", + "test": "cross-env NODE_ENV=test jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/jest-e2e.json" + "test:e2e": "cross-env NODE_ENV=test jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^10.0.0", @@ -29,9 +29,9 @@ "@nestjs/typeorm": "^10.0.0", "@types/dotenv": "^8.2.0", "@types/passport-jwt": "^3.0.13", + "aws-sdk": "^2.1499.0", "bcryptjs": "^2.4.3", "class-transformer": "^0.5.1", - "aws-sdk": "^2.1499.0", "class-validator": "^0.14.0", "dotenv": "^16.3.1", "mysql2": "^3.6.3", @@ -51,6 +51,7 @@ "@types/supertest": "^2.0.12", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", + "cross-env": "^7.0.3", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0",