mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
extract patch booking to db
This commit is contained in:
committed by
Thomas Ruoff
parent
ef7f80fd92
commit
d9cd2af314
12
db/index.ts
12
db/index.ts
@@ -76,6 +76,18 @@ export async function createBooking({
|
||||
return booking.toJSON()
|
||||
}
|
||||
|
||||
export async function patchBooking(
|
||||
bookingUUID: string,
|
||||
bookingData: Booking,
|
||||
): Promise<Booking> {
|
||||
await connect()
|
||||
const booking = await getBookingByUUID(bookingUUID)
|
||||
booking.set(bookingData);
|
||||
await booking.save()
|
||||
|
||||
return booking.toJSON()
|
||||
}
|
||||
|
||||
export async function createBill(
|
||||
bookingUUID: string,
|
||||
billData: Bill
|
||||
|
||||
@@ -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}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user