extract patch booking to db

This commit is contained in:
Thomas Ruoff
2022-03-14 23:52:32 +01:00
committed by Thomas Ruoff
parent ef7f80fd92
commit d9cd2af314
2 changed files with 15 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { BookingDocument } from '../../../../db/booking'
import { BOOKING_STATUS } from '../../../../db/enums'
import { getBookingByUUID } from '../../../../db/index'
import { patchBooking } from '../../../../db/index'
export default async function userHandler(
req: NextApiRequest,
@@ -18,8 +18,6 @@ export default async function userHandler(
switch (method) {
case 'PATCH':
booking = await getBookingByUUID(uuid)
if (!Object.values(BOOKING_STATUS).includes(req.body.status)) {
res
.status(400)
@@ -33,8 +31,8 @@ export default async function userHandler(
booking.set(req.body)
try {
await booking.save()
res.status(200).json(booking.toJSON())
const booking = await patchBooking(uuid, req.body);
res.status(200).json(booking)
} catch (error) {
res.status(400).end(`Failed to save booking: ${error.message}`)
}