mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
prettier all the things
This commit is contained in:
committed by
Thomas Ruoff
parent
c35d3009c6
commit
36f8719531
@@ -22,8 +22,8 @@ export type Booking = {
|
||||
purpose?: string
|
||||
org?: string
|
||||
destination?: string
|
||||
days?: string[],
|
||||
calendarEventId: string,
|
||||
days?: string[]
|
||||
calendarEventId: string
|
||||
}
|
||||
|
||||
export type BookingDocument = Booking &
|
||||
@@ -128,37 +128,43 @@ BookingSchema.pre('save', async function (next: () => void): Promise<void> {
|
||||
|
||||
if (!booking.calendarEventId) {
|
||||
// create calendar event before saving to database
|
||||
await createCalendarEvent(booking);
|
||||
} else if ([BOOKING_STATUS.CANCELED, BOOKING_STATUS.REJECTED].includes(booking.status)) {
|
||||
await createCalendarEvent(booking)
|
||||
} else if (
|
||||
[BOOKING_STATUS.CANCELED, BOOKING_STATUS.REJECTED].includes(booking.status)
|
||||
) {
|
||||
// event has been canceled or rejected, delete calendar event again to free up the slot
|
||||
await deleteCalendarEvent(booking);
|
||||
await deleteCalendarEvent(booking)
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
BookingSchema.static('findBookedDays', async function (
|
||||
uuidsToIngore: string[] = []
|
||||
): Promise<string[]> {
|
||||
const model = this as BookingModel
|
||||
const now = nowInTz()
|
||||
const bookedDays = await model
|
||||
.find(
|
||||
{
|
||||
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
||||
uuid: { $nin: uuidsToIngore },
|
||||
// dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway
|
||||
endDate: { $gt: dateFormatBackend(now) },
|
||||
},
|
||||
'days'
|
||||
)
|
||||
.exec()
|
||||
|
||||
return bookedDays
|
||||
.map((b) => b.days)
|
||||
.flat()
|
||||
.sort()
|
||||
next()
|
||||
})
|
||||
|
||||
BookingSchema.static(
|
||||
'findBookedDays',
|
||||
async function (uuidsToIngore: string[] = []): Promise<string[]> {
|
||||
const model = this as BookingModel
|
||||
const now = nowInTz()
|
||||
const bookedDays = await model
|
||||
.find(
|
||||
{
|
||||
status: { $in: [BOOKING_STATUS.REQUESTED, BOOKING_STATUS.CONFIRMED] },
|
||||
uuid: { $nin: uuidsToIngore },
|
||||
// dateFormatBackend uses YYYY-MM-DD, which is startOfDay anyway
|
||||
endDate: { $gt: dateFormatBackend(now) },
|
||||
},
|
||||
'days'
|
||||
)
|
||||
.exec()
|
||||
|
||||
return bookedDays
|
||||
.map((b) => b.days)
|
||||
.flat()
|
||||
.sort()
|
||||
}
|
||||
)
|
||||
|
||||
export default (mongoose.models.Booking ||
|
||||
mongoose.model<BookingDocument, BookingModel>('Booking', BookingSchema)) as BookingModel
|
||||
mongoose.model<BookingDocument, BookingModel>(
|
||||
'Booking',
|
||||
BookingSchema
|
||||
)) as BookingModel
|
||||
|
||||
Reference in New Issue
Block a user