Skip to content

Commit

Permalink
[BE#465]이미 존재하는 카테고리인 경우 에러
Browse files Browse the repository at this point in the history
  • Loading branch information
victolee0 authored Dec 14, 2023
1 parent d7e845a commit af8d25f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion BE/src/categories/categories.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ export class CategoriesService {
throw new NotFoundException('해당 id의 유저가 존재하지 않습니다.');
}

const categoryCount = await this.categoriesRepository.count({
const categories = await this.categoriesRepository.find({
where: { user_id: { id: user.id } },
});
const categoryCount = categories.length;
if (categoryCount >= CATEGORIES_MAXIMUM) {
throw new BadRequestException(
`카테고리는 최대 ${CATEGORIES_MAXIMUM}개까지 생성할 수 있습니다.`,
);
}
const categoryNames = categories.map((category) => category.name);
if (categoryNames.includes(categoriesData.name)) {
throw new BadRequestException('이미 존재하는 카테고리입니다.');
}

const category = this.categoriesRepository.create({
...categoriesData,
Expand Down

0 comments on commit af8d25f

Please sign in to comment.