From 0c838d07141e45face227b0431459ed09f2a456d Mon Sep 17 00:00:00 2001 From: DongHoonYu96 Date: Thu, 28 Nov 2024 11:26:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20[BE]=20=ED=80=B4=EC=A6=88=EC=85=8B?= =?UTF-8?q?=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 에러시 500 error --- BE/src/quiz-set/entities/quiz-set.entity.ts | 25 ++++++++++++++++++++- BE/src/quiz-set/quiz-set.controller.ts | 11 ++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/BE/src/quiz-set/entities/quiz-set.entity.ts b/BE/src/quiz-set/entities/quiz-set.entity.ts index 429b06d2..71b3efe2 100644 --- a/BE/src/quiz-set/entities/quiz-set.entity.ts +++ b/BE/src/quiz-set/entities/quiz-set.entity.ts @@ -4,6 +4,25 @@ import { UserModel } from '../../user/entities/user.entity'; import { QuizModel } from './quiz.entity'; import { UserQuizArchiveModel } from '../../user/entities/user-quiz-archive.entity'; +const CategoriesEnum = Object.freeze({ + GENERAL: 'GENERAL', + MOVIE: 'MOVIE', + MUSIC: 'MUSIC', + FOOD: 'FOOD', + ANIMAL: 'ANIMAL', + LANGUAGE: 'LANGUAGE', + NEWS: 'NEWS', + MATH: 'MATH', + SCIENCE: 'SCIENCE', + ECONOMY: 'ECONOMY', + HISTORY: 'HISTORY', + GEOGRAPHY: 'GEOGRAPHY', + SPORTS: 'SPORTS', + GAME: 'GAME', + IT: 'IT', + POLITIC: 'POLITIC' +}); + @Entity('quiz_set') export class QuizSetModel extends BaseModel { @Column() @@ -12,7 +31,11 @@ export class QuizSetModel extends BaseModel { @Column({ name: 'user_id' }) userId: number; - @Column() + @Column({ + type: 'enum', + enum: CategoriesEnum, + default: CategoriesEnum.GENERAL // 기본값 설정 가능 + }) category: string; @ManyToOne(() => UserModel, (user) => user.quizSetList, { diff --git a/BE/src/quiz-set/quiz-set.controller.ts b/BE/src/quiz-set/quiz-set.controller.ts index 0bb2d01a..22550252 100644 --- a/BE/src/quiz-set/quiz-set.controller.ts +++ b/BE/src/quiz-set/quiz-set.controller.ts @@ -4,12 +4,12 @@ import { DefaultValuePipe, Delete, Get, + Logger, Param, Patch, Post, Query, - UseGuards, - Logger + UseGuards } from '@nestjs/common'; import { ApiOperation, ApiResponse } from '@nestjs/swagger'; import { QuizSetService } from './service/quiz-set.service'; @@ -44,7 +44,12 @@ export class QuizSetController { @Query('take', new ParseIntOrDefault(10)) take: number, @Query('search', new DefaultValuePipe('')) search: string ) { - const result = await this.quizService.findAllWithQuizzesAndChoices(category, cursor, take, search); + const result = await this.quizService.findAllWithQuizzesAndChoices( + category, + cursor, + take, + search + ); this.logger.verbose(`퀴즈셋 목록 조회: ${result}`); return result; } From cbe298118a3ba755a2becf1e0db45233e8b297cd Mon Sep 17 00:00:00 2001 From: DongHoonYu96 Date: Thu, 28 Nov 2024 11:26:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20[BE]=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=98=A4=EB=A5=98=EC=8B=9C=20error=20msg=20?= =?UTF-8?q?=EA=B5=AC=EC=B2=B4=EC=A0=81=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/quiz-set/service/quiz-set-create.service.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BE/src/quiz-set/service/quiz-set-create.service.ts b/BE/src/quiz-set/service/quiz-set-create.service.ts index b54c26c8..0e05a984 100644 --- a/BE/src/quiz-set/service/quiz-set-create.service.ts +++ b/BE/src/quiz-set/service/quiz-set-create.service.ts @@ -110,6 +110,16 @@ export class QuizSetCreateService { } private handleError(error: Error): never { + const mysqlError = error as unknown as { + code: number; + errno: number; + sqlState: string; + sqlMessage: string; + }; + if (mysqlError.errno === 1265) { + throw new BadRequestException('퀴즈셋 생성 실패: 올바른 카테고리를 입력해주세요'); + } + if (error instanceof BadRequestException) { throw error; } From d5a9f9455de59a6c0cadfb82c49b5cc0fe090d9e Mon Sep 17 00:00:00 2001 From: DongHoonYu96 Date: Thu, 28 Nov 2024 11:30:21 +0900 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20[BE]=20=EC=A0=95=EC=B9=98=20?= =?UTF-8?q?=EB=AA=85=EC=82=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/quiz-set/entities/quiz-set.entity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BE/src/quiz-set/entities/quiz-set.entity.ts b/BE/src/quiz-set/entities/quiz-set.entity.ts index 71b3efe2..88fadbbd 100644 --- a/BE/src/quiz-set/entities/quiz-set.entity.ts +++ b/BE/src/quiz-set/entities/quiz-set.entity.ts @@ -20,7 +20,7 @@ const CategoriesEnum = Object.freeze({ SPORTS: 'SPORTS', GAME: 'GAME', IT: 'IT', - POLITIC: 'POLITIC' + POLITICS: 'POLITICS' }); @Entity('quiz_set')