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
@@ -64,6 +64,25 @@ BookingSchema.virtual('days').get(function () {
|
||||
return getDays({ startDate: this.startDate, endDate: this.endDate })
|
||||
})
|
||||
|
||||
BookingSchema.static('findBookedDays', async function (): string[] {
|
||||
console.log('in findBookedDays this is', this)
|
||||
const bookings = await this.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) => booking.days)
|
||||
.flat()
|
||||
.sort()
|
||||
})
|
||||
|
||||
const Model: mongoose.Model<Booking> =
|
||||
mongoose.models.Booking || mongoose.model('Booking', BookingSchema)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user