Adding endpoint to force performing a reservation

This commit is contained in:
Collin Duncan 2024-03-22 20:14:14 +01:00
parent 67c5374832
commit 7a022fccc1
No known key found for this signature in database

View file

@ -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)