further work on bills

This commit is contained in:
Thomas Ruoff
2020-10-05 22:02:02 +02:00
committed by Thomas Ruoff
parent ec1b2e9629
commit f8434233d9
4 changed files with 145 additions and 69 deletions

View File

@@ -86,12 +86,15 @@ export async function createBooking({
export async function createBill(bookingUUID: string, billData: BillDocument) {
await connect()
const bill = new Bill(billData)
const booking = await getBookingByUUID(bookingUUID)
bill.booking = booking._id
const bill =
(await Bill.findOne({ booking: booking._id })) ||
new Bill({ booking: booking._id })
bill.set(billData)
await bill.save()
await bill.populate('booking').execPopulate()
return bill.toJSON()
}