mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
make findBookedDays a static of schema
This commit is contained in:
committed by
Thomas Ruoff
parent
cf92a69fa7
commit
62a0e79664
22
db/index.ts
22
db/index.ts
@@ -20,22 +20,7 @@ function connect() {
|
||||
|
||||
export async function getBookedDays() {
|
||||
await connect()
|
||||
|
||||
const bookings = await Booking.find(
|
||||
{
|
||||
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
||||
$or: [
|
||||
{ endDate: { $gt: new Date() } },
|
||||
{ startDate: { $gt: new Date() } },
|
||||
],
|
||||
},
|
||||
'startDate endDate'
|
||||
).exec()
|
||||
|
||||
return bookings
|
||||
.map((booking) => booking.days)
|
||||
.flat()
|
||||
.sort()
|
||||
return Booking.findBookedDays()
|
||||
}
|
||||
|
||||
export async function getBookingByUUID(uuid: string) {
|
||||
@@ -62,10 +47,7 @@ export async function createBooking({
|
||||
|
||||
if (booking.days.some((day: string) => bookedDays.includes(day))) {
|
||||
const error = new mongoose.Error.ValidationError(booking)
|
||||
error.addError(
|
||||
'endDate',
|
||||
'At least on one day the van is not avaliable. Choose another startDate or endDate.'
|
||||
)
|
||||
error.addError('endDate', new mongoose.Error.ValidatorError())
|
||||
throw error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user