fix double booked day validation

This commit is contained in:
Thomas Ruoff
2020-12-23 23:38:53 +01:00
parent b723fc5660
commit 2a5c9b8638
4 changed files with 37 additions and 21 deletions

View File

@@ -1,9 +1,7 @@
import * as mongoose from 'mongoose'
import { getYear } from 'date-fns'
import BookerModel, { Booker } from './booker'
import BookingModel, { Booking } from './booking'
import BillModel, { Bill } from './bill'
import { dateFormatFrontend } from '../helpers/date'
import { BOOKING_STATUS } from './enums'
let connectedPromise: Promise<typeof mongoose>
@@ -66,20 +64,6 @@ export async function createBooking({
org,
destination,
})
const bookedDays = await getBookedDays()
const doubleBookedDays = booking.days.filter((day: string) =>
bookedDays.includes(day)
)
if (doubleBookedDays.length) {
const error = new mongoose.Error.ValidationError(booking.uuid)
error.errors.days = new mongoose.Error.ValidatorError(
`${doubleBookedDays
.map((dateString) => dateFormatFrontend(new Date(dateString)))
.join(', ')} schon gebucht`
)
throw error
}
let booker = await BookerModel.findOne({ email }).exec()
if (!booker) {