Skip to content

Commit

Permalink
태그 생성 시, 중복 검사 모듈 추가 (#493)
Browse files Browse the repository at this point in the history
* feat(tag): 디폴트 태그 생성 시 중복 검사하는 모듈 추가

디폴트 태그를 생성할 때, 기존의 서브 및 디폴트 태그와 내용이 같은지 확인함

* feat(tag): 슈퍼 태그 생성 시 중복 검사하는 모듈 추가

슈퍼 태그를 생성할 때, 기존의 슈퍼 태그와 내용이 같은지 확인함

* docs(tag): POST 스웨거 에러 코드 변경

POST에서 스웨거 에러 코드 변경
  • Loading branch information
nyj001012 committed Jun 8, 2023
1 parent 9895ad4 commit eb4b9aa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
20 changes: 16 additions & 4 deletions backend/src/routes/tags.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions backend/src/tags/tags.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand All @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions backend/src/tags/tags.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,28 @@ export class TagsService {
}
return true;
}

async isDuplicatedSubDefaultTag(content: string, bookInfoId: number): Promise<boolean> {
const subDefaultTag: VTagsSubDefault[] = await this.subTagRepository.getSubTags({
content,
bookInfoId,
});
if (subDefaultTag.length === 0) {
return false;
}
return true;
}

async isDuplicatedSuperTag(content: string, bookInfoId: number): Promise<boolean> {
const superTag: SuperTag[] = await this.superTagRepository.getSuperTags({
content,
bookInfoId,
});
if (superTag.length === 0) {
return false;
}
return true;
}
}

export default TagsService;
2 changes: 2 additions & 0 deletions backend/src/utils/error/errorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.';

0 comments on commit eb4b9aa

Please sign in to comment.