From 7e3370f7cbe79851c5ff3f9e87b1addc63d8c488 Mon Sep 17 00:00:00 2001 From: lua Date: Tue, 6 Dec 2022 15:45:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#39=20=EC=8B=A0=EA=B3=A0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95+=EC=8B=A0=EA=B3=A0=20=EC=B7=A8=EC=86=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...eportDto.ts => RequestCreateReport.dto.ts} | 0 src/report/dto/RequestDeleteReport.dto.ts | 6 ++++ src/report/report.controller.ts | 23 ++++++++++-- src/report/report.service.ts | 35 +++++++++++-------- 4 files changed, 48 insertions(+), 16 deletions(-) rename src/report/dto/{RequestCreateReportDto.ts => RequestCreateReport.dto.ts} (100%) create mode 100644 src/report/dto/RequestDeleteReport.dto.ts diff --git a/src/report/dto/RequestCreateReportDto.ts b/src/report/dto/RequestCreateReport.dto.ts similarity index 100% rename from src/report/dto/RequestCreateReportDto.ts rename to src/report/dto/RequestCreateReport.dto.ts diff --git a/src/report/dto/RequestDeleteReport.dto.ts b/src/report/dto/RequestDeleteReport.dto.ts new file mode 100644 index 0000000..0c5dc1d --- /dev/null +++ b/src/report/dto/RequestDeleteReport.dto.ts @@ -0,0 +1,6 @@ +import { ApiProperty } from "@nestjs/swagger"; + +export class RequestDeleteReportDto { + @ApiProperty() + report_id: string; +} \ No newline at end of file diff --git a/src/report/report.controller.ts b/src/report/report.controller.ts index 007280b..8174177 100644 --- a/src/report/report.controller.ts +++ b/src/report/report.controller.ts @@ -1,11 +1,12 @@ -import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; +import { Body, Controller, Delete, Get, HttpException, HttpStatus, Post, Query, Req, UseGuards } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; import { RolesGuard } from 'src/auth/guards/roles.guard'; import { Roles } from 'src/libs/decorators/roles.decorator'; import { Role } from 'src/libs/enums/role.enum'; import { ReportService } from './report.service'; -import { RequestCreateReportDto } from './dto/RequestCreateReportDto'; +import { RequestCreateReportDto } from './dto/RequestCreateReport.dto'; +import { RequestDeleteReportDto } from './dto/RequestDeleteReport.dto'; @ApiTags('report') @ApiBearerAuth() @@ -25,4 +26,22 @@ export class ReportController { body.post_id, ); } + + // 신고 취소 + @Delete() + @Roles([Role.User]) + async CancelReport(@Body() body: RequestDeleteReportDto, @Req() req) { + const user_id = req.user.user_id; + const post_id = req.post.post_id; + return await this.reportService + .deleteReport(user_id, post_id, body.report_id) + .catch((err) => { + throw new HttpException( + { + message: err.message, + }, + HttpStatus.BAD_REQUEST, + ); + }); + } } diff --git a/src/report/report.service.ts b/src/report/report.service.ts index 4e5803e..dba291c 100644 --- a/src/report/report.service.ts +++ b/src/report/report.service.ts @@ -22,16 +22,6 @@ export class ReportService { 0: 심한 욕설 1: 혐오 발언 2: 도배 3: 선정적인 게시물 4: 도박성 게시물 5: 광고성 게시물 */ - // 본인 게시글인지 확인 - checkWriter(user, post) { - // 본인 게시글이면 false - if (user.user_id == post.user_id.user_id) { - return false; - } - else - return true; - } - // 신고 async addReport(report_type: number, user_id: string, post_id: string) { const user = await this.userRepository.findOneBy({ @@ -60,11 +50,10 @@ export class ReportService { }); } - // 본인 게시물 조회 미포함 - if (this.checkWriter) { - return; - } + // 본인 게시물 신고 미포함 + if (user.user_id == post.user_id.user_id) return; + // report_type이 달라도 user, post id가 존재하면 이미 신고됨 const isReported = await this.reportRepository .createQueryBuilder('report') .where('report.user_id = :user_id', { user_id }) @@ -83,4 +72,22 @@ export class ReportService { return await this.reportRepository.save(rp); } + + // 신고 취소 + async deleteReport(user_id: string, post_id: string, report_id: string) { + let query = await this.reportRepository + .createQueryBuilder('report') + .where('report.user_id = :user_id', { user_id }) + .andWhere('report.post_id = :post_id', { post_id }) + .getOne(); + + // 본인이 신고한 게시글이 아니면 잘못된 요청 + if (query == null) + throw new BadRequestException({ + status: HttpStatus.BAD_REQUEST, + message: '잘못된 요청입니다.', + }); + + return await this.reportRepository.delete({ report_id }); + } }