remover booker, that's overdosed

It also brings the problem of consolidating bookers over multiple
bookings. The amount of data is not justifying having it in an own
entity
This commit is contained in:
Thomas Ruoff
2021-06-21 23:21:23 +02:00
parent 3700b5f450
commit 9f3b6bb2e1
13 changed files with 63 additions and 86 deletions

View File

@@ -1,5 +1,4 @@
import * as mongoose from 'mongoose'
import BookerModel, { Booker } from './booker'
import BookingModel, { Booking, BookingDocument } from './booking'
import BillModel, { Bill } from './bill'
import { BOOKING_STATUS } from './enums'
@@ -20,7 +19,9 @@ function connect(): Promise<typeof mongoose> {
return connectedPromise
}
export async function getBookedDays(uuidsToIngore?: string[]): Promise<string[]> {
export async function getBookedDays(
uuidsToIngore?: string[]
): Promise<string[]> {
await connect()
return BookingModel.findBookedDays(uuidsToIngore)
}
@@ -33,14 +34,14 @@ export async function getBookingByUUID(uuid: string): Promise<BookingDocument> {
export async function getBookings({
status = [BOOKING_STATUS.CONFIRMED, BOOKING_STATUS.REQUESTED],
startDateGreaterThan = '2000-01-01T00:00:00Z',
}: { status?: BOOKING_STATUS[]; startDateGreaterThan?: string } = {}): Promise<BookingDocument[]> {
}: { status?: BOOKING_STATUS[]; startDateGreaterThan?: string } = {}): Promise<
BookingDocument[]
> {
await connect()
return await BookingModel.find({
status: { $in: status },
startDate: { $gte: startDateGreaterThan },
})
.populate('booker')
.exec()
}).exec()
}
export async function createBooking({
@@ -55,7 +56,7 @@ export async function createBooking({
street,
zip,
city,
}: Booking & Booker): Promise<Booking> {
}: Booking): Promise<Booking> {
await connect()
const booking = new BookingModel({
startDate,
@@ -63,17 +64,15 @@ export async function createBooking({
purpose,
org,
destination,
name,
email,
phone,
street,
zip,
city,
})
let booker = await BookerModel.findOne({ email }).exec()
if (!booker) {
booker = new BookerModel({ name, email, phone, street, zip, city })
await booker.save()
}
booking.booker = booker._id
await booking.save()
await booking.populate('booker').execPopulate()
return booking.toJSON()
}