prettier all the things

This commit is contained in:
Thomas Ruoff
2022-02-19 23:18:49 +01:00
parent 4b918af23e
commit 9886cf29d2
28 changed files with 433 additions and 428 deletions

View File

@@ -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

View File

@@ -5,7 +5,7 @@ import { BOOKING_STATUS } from './enums'
let connectedPromise: Promise<mongoose.Mongoose>
export const MONGO_URI = process.env.MONGO_URI;
export const MONGO_URI = process.env.MONGO_URI
export const MONGODB_OPTIONS = {
useCreateIndex: true,
@@ -45,7 +45,9 @@ export async function getBookings({
return await BookingModel.find({
status: { $in: status },
startDate: { $gte: startDateGreaterThan },
}).sort({ startDate: -1 }).exec()
})
.sort({ startDate: -1 })
.exec()
}
export async function createBooking({