mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
also get booked days from calendar
This commit is contained in:
@@ -5,7 +5,6 @@ import { createCalendarEvent, deleteCalendarEvent } from '../lib/googlecalendar'
|
||||
|
||||
import { Bill } from './bill'
|
||||
import { BOOKING_STATUS, VALIDATION_ERRORS } from './enums'
|
||||
import { getBookedDays } from './index'
|
||||
|
||||
export type Booking = {
|
||||
uuid: string
|
||||
@@ -76,7 +75,7 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
validator: async function (days: string[]): Promise<boolean> {
|
||||
const booking = this as Booking
|
||||
const uuid = booking.uuid && [booking.uuid]
|
||||
const bookedDays = await getBookedDays(uuid)
|
||||
const bookedDays = await BookingModel.findBookedDays(uuid)
|
||||
|
||||
const doubleBookedDays = days.filter((day: string): boolean =>
|
||||
bookedDays.includes(day)
|
||||
@@ -155,8 +154,10 @@ BookingSchema.static(
|
||||
}
|
||||
)
|
||||
|
||||
export default (mongoose.models.Booking ||
|
||||
const BookingModel = (mongoose.models.Booking ||
|
||||
mongoose.model<BookingDocument, BookingModel>(
|
||||
'Booking',
|
||||
BookingSchema
|
||||
)) as BookingModel
|
||||
|
||||
export default BookingModel;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as mongoose from 'mongoose'
|
||||
import BookingModel, { Booking, BookingDocument } from './booking'
|
||||
import BillModel, { Bill } from './bill'
|
||||
import { getBookedDays as calendarGetBookedDays } from '../lib/googlecalendar'
|
||||
import { BOOKING_STATUS } from './enums'
|
||||
import { uniqueFilter } from '../helpers/array'
|
||||
|
||||
let connectedPromise: Promise<mongoose.Mongoose>
|
||||
|
||||
@@ -21,7 +23,12 @@ export async function getBookedDays(
|
||||
uuidsToIngore?: string[]
|
||||
): Promise<string[]> {
|
||||
await connect()
|
||||
return BookingModel.findBookedDays(uuidsToIngore)
|
||||
const bookedInDatabase = await BookingModel.findBookedDays(uuidsToIngore);
|
||||
const bookedInCalendar = await calendarGetBookedDays();
|
||||
|
||||
return [ ...bookedInDatabase, ...bookedInCalendar]
|
||||
.filter(uniqueFilter)
|
||||
.sort();
|
||||
}
|
||||
|
||||
export async function getBookingByUUID(uuid: string): Promise<BookingDocument> {
|
||||
|
||||
Reference in New Issue
Block a user