Skip to content

Commit

Permalink
update multiple accept logic
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Dec 26, 2023
1 parent a09a98e commit 1908370
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/popo/reservation/place/reserve.place.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Roles } from '../../../auth/authroization/roles.decorator';
import { RolesGuard } from '../../../auth/authroization/roles.guard';
import { PlaceService } from '../../place/place.service';
import {JwtPayload} from "../../../auth/strategies/jwt.payload";
import { ReservePlace } from './reserve.place.entity';

@ApiTags('Place Reservation')
@Controller('reservation-place')
Expand Down Expand Up @@ -196,8 +197,16 @@ export class ReservePlaceController {
@Body() body: AcceptPlaceReservationListDto,
@Query('sendEmail') sendEmail?: string,
) {
const reservations: ReservePlace[] = [];
for (const reservation_uuid of body.uuid_list) {
const reservation = await this.reservePlaceService.findOneByUuidOrFail(reservation_uuid);
reservations.push(reservation);
}

// early created reservation should be processed first
reservations.sort((a, b) => (a.created_at > b.created_at ? 1 : -1));

for (const reservation of reservations) {
await this.reservePlaceService.checkReservationPossible(
{
place_id: reservation.place_id,
Expand All @@ -208,7 +217,7 @@ export class ReservePlaceController {
reservation.booker_id,
)
const response = await this.reservePlaceService.updateStatus(
reservation_uuid,
reservation.uuid,
ReservationStatus.accept,
);

Expand Down
4 changes: 3 additions & 1 deletion src/popo/reservation/place/reserve.place.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ReservePlaceService {
private readonly placeService: PlaceService,
) {}

// TODO: delete this code, after concurrent check logic is fully validated
async isReservationOverlap(
place_id: string,
date: string,
Expand Down Expand Up @@ -131,6 +132,7 @@ export class ReservePlaceService {

const targetPlace = await this.placeService.findOneByUuidOrFail(place_id);

// TODO: delete this code, after concurrent check logic is fully validated
// Reservation Overlap Check
// const isReservationOverlap = await this.isReservationOverlap(
// place_id,
Expand All @@ -148,7 +150,7 @@ export class ReservePlaceService {
const isConcurrentPossible = await this.isReservationConcurrent(place_id, targetPlace.max_concurrent_reservation, date, start_time, end_time);
if (!isConcurrentPossible) {
throw new BadRequestException(
`"${targetPlace.name}" 장소에 이미 ${targetPlace.max_concurrent_reservation}개 예약이 있어 ${date} ${start_time} ~ ${end_time}에는 예약이 불가능 합니다.`
`"${targetPlace.name}" 장소에 이미 승인된 ${targetPlace.max_concurrent_reservation}개 예약이 있어 ${date} ${start_time} ~ ${end_time}에는 예약이 불가능 합니다.`
)
}

Expand Down

0 comments on commit 1908370

Please sign in to comment.