Skip to content

Commit

Permalink
modify addReaction
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Jan 12, 2024
1 parent 353f621 commit bca4328
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/notice/notice.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,26 +458,38 @@ export class NoticeRepository {
emoji: string,
userUuid: string,
): Promise<void> {
await this.prismaService.notice
.update({
where: { id, deletedAt: null },
data: {
reactions: {
connect: {
emoji_noticeId_userId: {
emoji,
noticeId: id,
userId: userUuid,
},
},
const reaction = await this.prismaService.reaction.findUnique({
where: {
emoji_noticeId_userId: {
emoji,
noticeId: id,
userId: userUuid,
},
},
});
if (reaction) {
await this.prismaService.reaction.update({
where: {
emoji_noticeId_userId: {
emoji,
noticeId: id,
userId: userUuid,
},
},
})
.catch((err) => {
this.logger.error('addReaction');
this.logger.debug(err);
throw new InternalServerErrorException('Database error');
data: {
deletedAt: null,
},
});
} else {
await this.prismaService.reaction.create({
data: {
emoji,
noticeId: id,
userId: userUuid,
deletedAt: null,
},
});
}
}

async removeReaction(
Expand Down

0 comments on commit bca4328

Please sign in to comment.