Skip to content

Commit

Permalink
modify/#66: modify error logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong committed Dec 10, 2023
1 parent 8438513 commit 94fcb5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class NoticePostsController {
remove(
@Param('noticePostId', ParsePositiveIntPipe) noticePostId: number,
@User() user: UserDto,
): Promise<string> {
): Promise<number> {
return this.noticePostService.remove(user.id, noticePostId);
}
}
20 changes: 12 additions & 8 deletions src/apis/notice-posts/services/notice-posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ export class NoticePostsService {
{ ...patchUpdateNoticePostDto },
);

const updatedBoard = await this.findOneOrNotFound(noticePostId);
const updatedBoard = await entityManager
.withRepository(this.noticePostRepository)
.findOneOrFail({ where: { id: noticePostId } });

await this.noticePostHistoryService.create(
entityManager,
Expand Down Expand Up @@ -261,7 +263,7 @@ export class NoticePostsService {
}
}

async remove(userId: number, noticePostId: number): Promise<string> {
async remove(userId: number, noticePostId: number): Promise<number> {
const existPost = await this.findOneOrNotFound(noticePostId);

if (existPost.userId !== userId) {
Expand All @@ -277,22 +279,24 @@ export class NoticePostsService {
try {
const entityManager = queryRunner.manager;

await this.noticePostRepository.update(
{ id: noticePostId },
{ status: NoticePostStatus.Remove },
);
await entityManager
.withRepository(this.noticePostRepository)
.update({ id: noticePostId }, { status: NoticePostStatus.Remove });

await this.noticePostHistoryService.create(
entityManager,
userId,
noticePostId,
HistoryAction.Delete,
{ ...existPost },
{
...existPost,
status: NoticePostStatus.Remove,
},
);

await queryRunner.commitTransaction();

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

0 comments on commit 94fcb5a

Please sign in to comment.