mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
another try to fix types for models
This commit is contained in:
committed by
Thomas Ruoff
parent
82270e944c
commit
038e2b2420
@@ -1,14 +1,14 @@
|
||||
import * as mongoose from 'mongoose'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { dateFormatBackend, getDays } from '../helpers/date'
|
||||
import { Booker } from './booker'
|
||||
import { BookerDocument } from './booker'
|
||||
import { BOOKING_STATUS } from './bookingStatus'
|
||||
|
||||
export interface Booking
|
||||
export interface BookingDocument
|
||||
extends mongoose.Document,
|
||||
mongoose.SchemaTimestampsConfig {
|
||||
uuid: string
|
||||
booker: Booker
|
||||
booker: BookerDocument
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
status: BOOKING_STATUS
|
||||
@@ -18,7 +18,11 @@ export interface Booking
|
||||
days?: string[]
|
||||
}
|
||||
|
||||
const BookingSchema = new mongoose.Schema<Booking>(
|
||||
export interface BookingModel extends mongoose.Model<BookingDocument> {
|
||||
findBookedDays(): Promise<string[]>
|
||||
}
|
||||
|
||||
const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
{
|
||||
// need a seperate uuid to be able to target a booking anonimously
|
||||
uuid: {
|
||||
@@ -78,12 +82,14 @@ BookingSchema.static('findBookedDays', async function (): Promise<string[]> {
|
||||
).exec()
|
||||
|
||||
return bookings
|
||||
.map((booking: Booking) => booking.days)
|
||||
.map((booking: BookingDocument) => booking.days)
|
||||
.flat()
|
||||
.sort()
|
||||
})
|
||||
|
||||
const Model: mongoose.Model<Booking> =
|
||||
mongoose.models.Booking || mongoose.model('Booking', BookingSchema)
|
||||
const Model: BookingModel = mongoose.model<BookingDocument, BookingModel>(
|
||||
'Booking',
|
||||
BookingSchema
|
||||
)
|
||||
|
||||
export default Model
|
||||
|
||||
Reference in New Issue
Block a user