From 7a022fccc1269db6c51debaa8052bce667291c41 Mon Sep 17 00:00:00 2001 From: Collin Duncan <3679940+cgduncan7@users.noreply.github.com> Date: Fri, 22 Mar 2024 20:14:14 +0100 Subject: [PATCH] Adding endpoint to force performing a reservation --- src/reservations/controller.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/reservations/controller.ts b/src/reservations/controller.ts index dfca529..0121d6d 100644 --- a/src/reservations/controller.ts +++ b/src/reservations/controller.ts @@ -5,6 +5,7 @@ import { Controller, Delete, Get, + HttpException, Inject, Param, Post, @@ -102,7 +103,6 @@ export class ReservationsController { @Post() async createReservation(@Body() req: CreateReservationRequest) { - console.log(req) const reservation = await this.reservationsService.create(req) if (!reservation.isAvailableForReservation()) { this.loggerService.debug('Reservation not available for reservation') @@ -113,6 +113,18 @@ export class ReservationsController { return 'Reservation queued' } + @Post(':id') + async performReservation(@Param('id') id: string) { + const reservation = await this.reservationsService.getById(id) + if (reservation == null) throw new HttpException('Not found', 404) + + if (!reservation.isAvailableForReservation()) + throw new HttpException('Not available', 400) + + await this.reservationsQueue.add(reservation) + return 'Reservation queued' + } + @Delete(':id') async deleteReservationById(@Param('id') id: string) { await this.reservationsService.deleteById(id)