Skip to content

Commit

Permalink
✨게시글 삭제 생성자만 가능 처리 및 카멜케이스 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhbenecia committed Nov 22, 2023
1 parent 53e96b7 commit 2f3cf2b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/backend/src/mogaco/mogaco.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Member, Mogaco } from '@prisma/client';
import { CreateMogacoDto, MogacoDto } from './dto';
import { MogacoStatusValidationPipe } from './pipes/mogaco-status-validation.pipe';
import { MogacoStatus } from './dto/mogaco-status.enum';
import { AtGuard } from 'src/auth/guards/at.guard';
import { GetUser } from 'libs/decorators/get-user.decorator';
import { AtGuard } from 'src/auth/guards/at.guard';

@Controller('mogaco')
@UseGuards(AtGuard)
Expand All @@ -28,8 +28,8 @@ export class MogacoController {
}

@Delete('/:id')
async deleteMogaco(@Param('id', ParseIntPipe) id: number): Promise<void> {
return this.mogacoService.deleteMogaco(id);
async deleteMogaco(@Param('id', ParseIntPipe) id: number, @GetUser() member: Member): Promise<void> {
return this.mogacoService.deleteMogaco(id, member);
}

@Patch('/:id/status')
Expand Down
18 changes: 11 additions & 7 deletions app/backend/src/mogaco/mogaco.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { ForbiddenException, Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../libs/utils/prisma.service';
import { Member, Mogaco } from '@prisma/client';
import { MogacoStatus } from './dto/mogaco-status.enum';
Expand All @@ -23,26 +23,26 @@ export class MogacoRepository {

return {
id: mogaco.id,
group_id: mogaco.group_id,
groupId: mogaco.groupId,
title: mogaco.title,
contents: mogaco.contents,
date: mogaco.date,
max_human_count: mogaco.max_human_count,
maxHumanCount: mogaco.maxHumanCount,
address: mogaco.address,
status: mogaco.status,
};
}

async createMogaco(createMogacoDto: CreateMogacoDto, member: Member): Promise<Mogaco> {
try {
const { group_id, title, contents, max_human_count, address, date } = createMogacoDto;
const { groupId, title, contents, maxHumanCount, address, date } = createMogacoDto;

const mogaco = await this.prisma.mogaco.create({
data: {
group_id,
groupId,
title,
contents,
max_human_count,
maxHumanCount,
address,
status: MogacoStatus.RECRUITING,
date: new Date(date),
Expand All @@ -61,7 +61,7 @@ export class MogacoRepository {
}
}

async deleteMogaco(id: number): Promise<void> {
async deleteMogaco(id: number, member: Member): Promise<void> {
const mogaco = await this.prisma.mogaco.findUnique({
where: { id },
});
Expand All @@ -70,6 +70,10 @@ export class MogacoRepository {
throw new NotFoundException(`Mogaco with id ${id} not found`);
}

if (mogaco.memberId !== member.id) {
throw new ForbiddenException(`You do not have permission to delete this Mogaco`);
}

await this.prisma.mogaco.delete({
where: { id },
});
Expand Down
4 changes: 2 additions & 2 deletions app/backend/src/mogaco/mogaco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class MogacoService {
return this.mogacoRepository.createMogaco(createMogaco, member);
}

async deleteMogaco(id: number): Promise<void> {
return this.mogacoRepository.deleteMogaco(id);
async deleteMogaco(id: number, member: Member): Promise<void> {
return this.mogacoRepository.deleteMogaco(id, member);
}

async updateMogacoStatus(id: number, status: MogacoStatus): Promise<Mogaco> {
Expand Down

0 comments on commit 2f3cf2b

Please sign in to comment.