mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix double booked day validation
This commit is contained in:
16
db/index.ts
16
db/index.ts
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user