Skip to content

Commit

Permalink
fix reservation check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Jan 28, 2024
1 parent 6acdcf5 commit 789ea63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/popo/reservation/place/reserve.place.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ReservePlaceController {
) {
const user = req.user as JwtPayload;

return this.reservePlaceService.checkReservationPossible(dto, user.uuid);
return this.reservePlaceService.checkReservationPossible(dto, user.uuid, false);
}

@Post()
Expand All @@ -57,7 +57,7 @@ export class ReservePlaceController {
const user = req.user as JwtPayload;
const existPlace = await this.placeService.findOneByUuidOrFail(dto.place_id);

await this.reservePlaceService.checkReservationPossible(dto, user.uuid);
await this.reservePlaceService.checkReservationPossible(dto, user.uuid, false);

const new_reservation = await this.reservePlaceService.save(
Object.assign(dto, { booker_id: user.uuid }),
Expand Down Expand Up @@ -215,6 +215,7 @@ export class ReservePlaceController {
end_time: reservation.end_time,
},
reservation.booker_id,
true,
)
const response = await this.reservePlaceService.updateStatus(
reservation.uuid,
Expand Down Expand Up @@ -254,6 +255,7 @@ export class ReservePlaceController {
end_time: reservation.end_time,
},
reservation.booker_id,
true
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/popo/reservation/place/reserve.place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class ReservePlaceService {
return true;
}

async checkReservationPossible(dto: DeepPartial<CreateReservePlaceDto>, booker_id: string) {
async checkReservationPossible(dto: DeepPartial<CreateReservePlaceDto>, booker_id: string, isPatch: boolean = true) {
const { place_id, date, start_time, end_time } = dto;

if (
Expand Down Expand Up @@ -179,12 +179,13 @@ export class ReservePlaceService {
)
}


const reservationsOfDay = await this.reservePlaceRepo.find({
where: {
booker_id: booker_id,
place_id: place_id,
date: date,
status: In([ReservationStatus.accept, ReservationStatus.in_process]),
status: In(isPatch ? [ReservationStatus.accept] : [ReservationStatus.accept, ReservationStatus.in_process]),
},
});

Expand Down

0 comments on commit 789ea63

Please sign in to comment.