Skip to content

Commit

Permalink
modify/#66: modify remove logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong committed Dec 9, 2023
1 parent a55fc3a commit 4b180bd
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/apis/notice-posts/services/notice-posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,46 +273,48 @@ export class NoticePostsService {
}
const queryRunner = this.dataSource.createQueryRunner();

queryRunner.connect();
queryRunner.startTransaction();
await queryRunner.connect();
await queryRunner.startTransaction();

try {
const entityManager = queryRunner.manager;

const isRemove = await this.noticePostRepository.update(
await this.noticePostRepository.update(
{ id: noticePostId },
{ status: NoticePostStatus.Remove },
);

if (!isRemove.affected) {
throw new HttpInternalServerErrorException({
code: COMMON_ERROR_CODE.SERVER_ERROR,
ctx: '게시글 삭제 중 알 수 없는 에러 발생',
});
}
await queryRunner.commitTransaction();

const removedPost = await this.findOneOrNotFound(noticePostId);

await this.noticePostHistoryService.create(
entityManager,
userId,
noticePostId,
HistoryAction.Delete,
{ ...existPost },
{ ...removedPost },
);

return '게시글 삭제 완료';
await queryRunner.commitTransaction();

return '공지게시글 삭제 완료';
} catch (error) {
if (queryRunner.isTransactionActive) {
queryRunner.rollbackTransaction();
await queryRunner.rollbackTransaction();
}

console.error(error);

throw new HttpInternalServerErrorException({
code: COMMON_ERROR_CODE.SERVER_ERROR,
stack: error.stack,
ctx: '게시글 업데이트 중 알 수 없는 에러 발생',
ctx: '공지게시글 업데이트 중 알 수 없는 에러 발생',
});
} finally {
queryRunner.release();
if (!queryRunner.isReleased) {
await queryRunner.release();
}
}
}
}

0 comments on commit 4b180bd

Please sign in to comment.