Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

496 patch tagsbookinfoidmerge body 중 supertagid null 값 허용안함 #498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions backend/src/tags/tags.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 (
Expand Down
11 changes: 6 additions & 5 deletions backend/src/tags/tags.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -199,6 +199,7 @@ export class TagsService {
} finally {
await this.queryRunner.release();
}
return superTagId;
}

async isExistingSuperTag(superTagId: number, content: string): Promise<boolean> {
Expand Down