diff --git a/backend/src/tags/tags.controller.ts b/backend/src/tags/tags.controller.ts index d7dd5f70..4098f939 100644 --- a/backend/src/tags/tags.controller.ts +++ b/backend/src/tags/tags.controller.ts @@ -136,12 +136,13 @@ export const mergeTags = async ( const superTagId: number = Number(req?.body?.superTagId); const subTagIds: number[] = req?.body?.subTagIds; const tagsService = new TagsService(); + let returnSuperTagId = 0; if (await tagsService.isValidBookInfoId(bookInfoId) === false) { await tagsService.releaseConnection(); return next(new ErrorResponse(errorCode.INVALID_BOOKINFO_ID, 400)); } - if (superTagId !== null + if (superTagId !== 0 && await tagsService.isValidSuperTagId(superTagId, bookInfoId) === false) { await tagsService.releaseConnection(); return next(new ErrorResponse(errorCode.INVALID_TAG_ID, 400)); @@ -151,13 +152,18 @@ export const mergeTags = async ( return next(new ErrorResponse(errorCode.INVALID_TAG_ID, 400)); } try { - await tagsService.mergeTags(bookInfoId, subTagIds, superTagId, parseInt(tokenId, 10)); + returnSuperTagId = await tagsService.mergeTags( + bookInfoId, + subTagIds, + superTagId, + parseInt(tokenId, 10), + ); } catch (e) { return next(new ErrorResponse(errorCode.UPDATE_FAIL_TAGS, 500)); } finally { await tagsService.releaseConnection(); } - return res.status(status.OK).send({ id: superTagId }); + return res.status(status.OK).send({ id: returnSuperTagId }); }; export const updateSuperTags = async ( diff --git a/backend/src/tags/tags.service.ts b/backend/src/tags/tags.service.ts index 7e62b6ac..6ad36027 100644 --- a/backend/src/tags/tags.service.ts +++ b/backend/src/tags/tags.service.ts @@ -129,8 +129,8 @@ export class TagsService { const superTag = await this.superTagRepository.getSuperTags({ id: superTagId }); const superLogin: string | null = await this.superTagRepository.getSuperTagLogin(superTagId); - if (superLogin === null) throw new Error(errorCode.CREATE_FAIL_TAGS); - + if (superLogin === null) + throw new Error(errorCode.CREATE_FAIL_TAGS); superTagsInsertion = { id: superTag[0].id, content: superTag[0].content, @@ -178,14 +178,14 @@ export class TagsService { async mergeTags( bookInfoId: number, subTagIds: number[], - rawSuperTagId: number | null, + rawSuperTagId: number, userId: number, ) { - let superTagId: number | null = 0; + let superTagId: number = 0; try { await this.queryRunner.startTransaction(); - if (rawSuperTagId === null) { + if (rawSuperTagId === 0) { const defaultTag = await this.superTagRepository.getDefaultTag(bookInfoId); if (defaultTag === null) { superTagId = await this.superTagRepository.createSuperTag('default', bookInfoId, userId); @@ -199,6 +199,7 @@ export class TagsService { } finally { await this.queryRunner.release(); } + return superTagId; } async isExistingSuperTag(superTagId: number, content: string): Promise {