mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
further work on billing
This commit is contained in:
committed by
Thomas Ruoff
parent
f8434233d9
commit
c396cdcbf9
30
db/index.ts
30
db/index.ts
@@ -27,8 +27,8 @@ export async function getBookedDays() {
|
||||
|
||||
export async function getBookingByUUID(uuid: string) {
|
||||
await connect()
|
||||
const booking = await Booking.findOne({ uuid })
|
||||
return booking?.populate('booker').execPopulate()
|
||||
return Booking.findOne({ uuid })
|
||||
//return booking.populate('bill').populate('booker').execPopulate()
|
||||
}
|
||||
|
||||
export async function getBookings() {
|
||||
@@ -87,14 +87,32 @@ export async function createBooking({
|
||||
export async function createBill(bookingUUID: string, billData: BillDocument) {
|
||||
await connect()
|
||||
const booking = await getBookingByUUID(bookingUUID)
|
||||
const bill =
|
||||
(await Bill.findOne({ booking: booking._id })) ||
|
||||
new Bill({ booking: booking._id })
|
||||
|
||||
const bill = new Bill()
|
||||
bill.set(billData)
|
||||
|
||||
await bill.save()
|
||||
await bill.populate('booking').execPopulate()
|
||||
|
||||
booking.bill = bill._id
|
||||
await booking.save()
|
||||
|
||||
return bill.toJSON()
|
||||
}
|
||||
|
||||
export async function patchBill(bookingUUID: string, billData: BillDocument) {
|
||||
await connect()
|
||||
const booking = await getBookingByUUID(bookingUUID)
|
||||
const bill =
|
||||
(booking.bill && (await Bill.findById(booking.bill))) ||
|
||||
(await Bill.create())
|
||||
|
||||
bill.set(billData)
|
||||
await bill.save()
|
||||
|
||||
if (booking.bill !== bill._id) {
|
||||
booking.bill = bill._id
|
||||
await booking.save()
|
||||
}
|
||||
|
||||
return bill.toJSON()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user