Skip to content

Commit 8c2403d

Browse files
committed
feat: reply power delete
1 parent eb64cec commit 8c2403d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

apps/server/src/replies/replies.controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Patch,
88
Post,
99
Query,
10+
Req,
1011
UseGuards,
1112
UseInterceptors,
1213
} from '@nestjs/common';
@@ -68,10 +69,10 @@ export class RepliesController {
6869

6970
@Delete(':replyId')
7071
@DeleteReplySwagger()
71-
@UseGuards(SessionTokenValidationGuard, ReplyExistenceGuard, ReplyOwnershipGuard)
72-
async delete(@Param('replyId', ParseIntPipe) replyId: number, @Query() data: BaseDto) {
73-
const { questionId } = await this.repliesService.deleteReply(replyId);
72+
@UseGuards(SessionTokenValidationGuard, ReplyExistenceGuard)
73+
async delete(@Param('replyId', ParseIntPipe) replyId: number, @Query() data: BaseDto, @Req() request: Request) {
7474
const { sessionId, token } = data;
75+
const { questionId } = await this.repliesService.deleteReply(replyId, token, request['reply']);
7576
const resultForOther = { replyId, questionId };
7677
this.socketGateway.broadcastReplyDelete(sessionId, token, resultForOther);
7778
return {};

apps/server/src/replies/replies.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { create } from 'node:domain';
2-
3-
import { Injectable } from '@nestjs/common';
1+
import { ForbiddenException, Injectable } from '@nestjs/common';
2+
import { Reply } from '@prisma/client';
43

54
import { CreateReplyDto } from './dto/create-reply.dto';
65
import { UpdateReplyBodyDto } from './dto/update-reply.dto';
@@ -39,7 +38,11 @@ export class RepliesService {
3938
return await this.repliesRepository.updateBody(replyId, body);
4039
}
4140

42-
async deleteReply(replyId: number) {
41+
async deleteReply(replyId: number, token: string, reply: Reply) {
42+
const { isHost } = await this.sessionAuthRepository.findByToken(token);
43+
44+
if (!isHost && reply.createUserToken !== token) throw new ForbiddenException('권한이 없습니다.');
45+
4346
return await this.repliesRepository.deleteReply(replyId);
4447
}
4548

0 commit comments

Comments
 (0)