Skip to content

Commit

Permalink
ADD: 일정 삭제 API
Browse files Browse the repository at this point in the history
  • Loading branch information
leehj050211 committed Sep 29, 2022
1 parent 2f24172 commit a45fc7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/calendar/calendar.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, UseGuards, Post, Body, Get, Param, Put } from '@nestjs/common';
import { Controller, UseGuards, Post, Body, Get, Param, Put, Delete } from '@nestjs/common';
import JwtAuthGuard from 'src/auth/auth.guard';
import { GetUser } from 'src/auth/getUser.decorator';
import { User } from 'src/auth/user';
Expand Down Expand Up @@ -40,4 +40,12 @@ export class CalendarController {
): Promise<void> {
return this.calendarservice.updateCalendar(user, dto);
}

@Delete(':id')
deleteCalendar(
@GetUser() user: User,
@Param('id') id: number
): Promise<void> {
return this.calendarservice.deleteCalendar(user, id);
}
}
8 changes: 8 additions & 0 deletions src/calendar/calendar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export class CalendarService {
this.calendarRepository.save(calendar);
}

async deleteCalendar(user: User, id: number): Promise<void> {
const calendar: CalendarEntity = await this.calendarRepository.findOne({
where: {id}
});
if (calendar.usercode !== user.usercode) throw new ForbiddenException('No permission');
this.calendarRepository.delete(calendar);
}

private initTodayDate(): Date {
const todayDate = new Date;
todayDate.setHours(0);
Expand Down

0 comments on commit a45fc7e

Please sign in to comment.