Skip to content

Commit

Permalink
fix date compare logic
Browse files Browse the repository at this point in the history
considering date, start_time when compare reservation time with current time
  • Loading branch information
khkim6040 committed Feb 8, 2024
1 parent 1d0bca6 commit 5de488d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/popo/reservation/place/reserve.place.controller.ts
Original file line number Diff line number Diff line change
@@ -286,10 +286,14 @@ export class ReservePlaceController {
await this.reservePlaceService.remove(uuid);
} else {
if (reservation.booker_id == user.uuid) {
if(reservation.start_time < new Date().toISOString()) {
// if reservation is in the past, deny delete
const reservation_time = reservation.date + reservation.start_time;
const current_time = new Date().toISOString().replace(/[-T:]/g, '').slice(0, 12);
if (reservation_time < current_time) {
throw new BadRequestException('Cannot delete past reservation');
} else {
await this.reservePlaceService.remove(uuid);
}
await this.reservePlaceService.remove(uuid);
} else {
throw new UnauthorizedException('Unauthorized delete action');
}

0 comments on commit 5de488d

Please sign in to comment.