From 757396e308907f2286450d1b9c2f8615c3b56cb8 Mon Sep 17 00:00:00 2001 From: Yeongbin Im <56269396+yeongbinim@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:49:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20user=20id=EA=B8=B0=EB=B0=98=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/categories/categories.controller.ts | 4 +--- BE/src/categories/categories.service.ts | 8 +++----- BE/src/categories/dto/response/category.dto.ts | 2 +- BE/src/study-logs/study-logs.entity.ts | 1 + 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/BE/src/categories/categories.controller.ts b/BE/src/categories/categories.controller.ts index 97f1625..807b812 100644 --- a/BE/src/categories/categories.controller.ts +++ b/BE/src/categories/categories.controller.ts @@ -40,9 +40,7 @@ export class CategoriesController { description: '잘못된 요청입니다.', }) getCategories(@User('id') user_id: number): Promise { - // TODO: 유저 id를 받아올 방식 정하기 - user_id; - return this.categoriesService.findByUserId(1); + return this.categoriesService.findByUserId(user_id); } @Post() diff --git a/BE/src/categories/categories.service.ts b/BE/src/categories/categories.service.ts index 49992d3..b2070f8 100644 --- a/BE/src/categories/categories.service.ts +++ b/BE/src/categories/categories.service.ts @@ -27,10 +27,6 @@ export class CategoriesService { return this.entityToDto(savedCategory); } - async findAll(): Promise { - return this.categoriesRepository.find(); - } - async findByUserId(user_id: number): Promise { const categories = await this.categoriesRepository.find({ where: { user_id: { id: user_id } }, @@ -47,6 +43,7 @@ export class CategoriesService { categoriesData: CategoryUpdateDto, id: number, ): Promise { + // todo - user_id를 검증 const category = await this.categoriesRepository.findOne({ where: { id }, relations: ['user_id'], @@ -58,6 +55,7 @@ export class CategoriesService { } async remove(user_id: number, id: number): Promise { + // todo - user_id를 검증 const result = await this.categoriesRepository.delete(id); if (result.affected === 0) { throw new NotFoundException('해당 카테고리가 존재하지 않습니다.'); @@ -66,7 +64,7 @@ export class CategoriesService { entityToDto(category: Categories): CategoryDto { const categoryDto: CategoryDto = { - id: category.id, + category_id: category.id, name: category.name, color_code: category.color_code, }; diff --git a/BE/src/categories/dto/response/category.dto.ts b/BE/src/categories/dto/response/category.dto.ts index 770e5e8..873f9a2 100644 --- a/BE/src/categories/dto/response/category.dto.ts +++ b/BE/src/categories/dto/response/category.dto.ts @@ -6,7 +6,7 @@ export class CategoryDto { example: '1', description: '카테고리 id', }) - id: number; + category_id: number; @ApiProperty({ type: 'string', diff --git a/BE/src/study-logs/study-logs.entity.ts b/BE/src/study-logs/study-logs.entity.ts index df8c910..7d187ff 100644 --- a/BE/src/study-logs/study-logs.entity.ts +++ b/BE/src/study-logs/study-logs.entity.ts @@ -31,6 +31,7 @@ export class StudyLogs { @ManyToOne(() => Categories, (categories) => categories.study_logs, { eager: true, + nullable: true, }) @JoinColumn({ name: 'category_id' }) category_id: Categories;