diff --git a/backend/src/routes/tags.routes.ts b/backend/src/routes/tags.routes.ts index 60e6aa19..f54f3ccb 100644 --- a/backend/src/routes/tags.routes.ts +++ b/backend/src/routes/tags.routes.ts @@ -296,9 +296,15 @@ router * schema: * type: object * examples: - * 유효하지 않은 content 길이 : + * 유효하지 않은 content 형식 : * value: - * errorCode: 910 + * errorCode: 900 + * 유효하지 않은 bookInfoId: + * value: + * errorCode: 907 + * 디폴트 태그의 내용이 중복됨: + * value: + * errorCode: 909 * '401': * description: 권한 없음. * content: @@ -356,9 +362,15 @@ router * schema: * type: object * examples: - * 유효하지 않은 content 길이 : + * 유효하지 않은 content 형식 : + * value: + * errorCode: 900 + * 유효하지 않은 bookInfoId: + * value: + * errorCode: 907 + * 슈퍼 태그의 내용이 중복됨: * value: - * errorCode: 910 + * errorCode: 908 * '401': * description: 권한 없음. * content: diff --git a/backend/src/tags/tags.controller.ts b/backend/src/tags/tags.controller.ts index ae8ff24c..6c75c013 100644 --- a/backend/src/tags/tags.controller.ts +++ b/backend/src/tags/tags.controller.ts @@ -17,11 +17,15 @@ export const createDefaultTags = async ( const content = req?.body?.content.trim(); const tagsService = new TagsService(); const regex: RegExp = /[^가-힣a-zA-Z0-9_]/g; + if (content === '' || content.length > 42 || regex.test(content) === true) { + return next(new ErrorResponse(errorCode.INVALID_INPUT_TAGS, 400)); + } if (await tagsService.isValidBookInfoId(parseInt(bookInfoId, 10)) === false) { return next(new ErrorResponse(errorCode.INVALID_BOOKINFO_ID, 400)); } - if (content === '' || content.length > 42 || regex.test(content) === true) - return next(new ErrorResponse(errorCode.INVALID_INPUT_TAGS, 400)); + if (await tagsService.isDuplicatedSubDefaultTag(content, bookInfoId)) { + return next(new ErrorResponse(errorCode.DUPLICATED_SUB_DEFAULT_TAGS, 400)); + } await tagsService.createDefaultTags(tokenId, bookInfoId, content); return res.status(status.CREATED).send(); }; @@ -36,11 +40,14 @@ export const createSuperTags = async ( const content = req?.body?.content.trim(); const tagsService = new TagsService(); const regex: RegExp = /[^가-힣a-zA-Z0-9_]/g; + if (content === '' || content === 'default' || content.length > 42 || regex.test(content) === true) { + return next(new ErrorResponse(errorCode.INVALID_INPUT_TAGS, 400)); + } if (await tagsService.isValidBookInfoId(parseInt(bookInfoId, 10)) === false) { return next(new ErrorResponse(errorCode.INVALID_BOOKINFO_ID, 400)); } - if (content === '' || content === 'default' || content.length > 42 || regex.test(content) === true) { - return next(new ErrorResponse(errorCode.INVALID_INPUT_TAGS, 400)); + if (await tagsService.isDuplicatedSuperTag(content, bookInfoId)) { + return next(new ErrorResponse(errorCode.DUPLICATED_SUPER_TAGS, 400)); } const superTagInsertion = await tagsService.createSuperTags(tokenId, bookInfoId, content); diff --git a/backend/src/tags/tags.service.ts b/backend/src/tags/tags.service.ts index 73701555..2d1bf86e 100644 --- a/backend/src/tags/tags.service.ts +++ b/backend/src/tags/tags.service.ts @@ -267,6 +267,28 @@ export class TagsService { } return true; } + + async isDuplicatedSubDefaultTag(content: string, bookInfoId: number): Promise { + const subDefaultTag: VTagsSubDefault[] = await this.subTagRepository.getSubTags({ + content, + bookInfoId, + }); + if (subDefaultTag.length === 0) { + return false; + } + return true; + } + + async isDuplicatedSuperTag(content: string, bookInfoId: number): Promise { + const superTag: SuperTag[] = await this.superTagRepository.getSuperTags({ + content, + bookInfoId, + }); + if (superTag.length === 0) { + return false; + } + return true; + } } export default TagsService; diff --git a/backend/src/utils/error/errorCode.ts b/backend/src/utils/error/errorCode.ts index 6f72555e..018ff66e 100644 --- a/backend/src/utils/error/errorCode.ts +++ b/backend/src/utils/error/errorCode.ts @@ -81,6 +81,8 @@ export const CREATE_FAIL_TAGS = '904'; export const UPDATE_FAIL_TAGS = '905'; export const DEFAULT_TAG_ID = '906'; export const INVALID_BOOKINFO_ID = '907'; +export const DUPLICATED_SUPER_TAGS = '908'; +export const DUPLICATED_SUB_DEFAULT_TAGS = '909'; export const INVALID_TAG_ID = '910'; export const CLIENT_AUTH_FAILED_ERROR_MESSAGE = 'Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.';