mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
use types instead of interfaces
This commit is contained in:
@@ -7,25 +7,24 @@ import { Booker } from './booker'
|
||||
import { BOOKING_STATUS, VALIDATION_ERRORS } from './enums'
|
||||
import { getBookedDays } from './index'
|
||||
|
||||
export interface Booking {
|
||||
export type Booking = {
|
||||
uuid: string
|
||||
booker: Booker
|
||||
bill: Bill
|
||||
booker?: Booker
|
||||
bill?: Bill
|
||||
startDate: string
|
||||
endDate: string
|
||||
status: BOOKING_STATUS
|
||||
status?: BOOKING_STATUS
|
||||
purpose?: string
|
||||
org?: string
|
||||
destination?: string
|
||||
days?: string[]
|
||||
}
|
||||
|
||||
export interface BookingDocument
|
||||
extends Booking,
|
||||
mongoose.Document,
|
||||
mongoose.SchemaTimestampsConfig { }
|
||||
export type BookingDocument = Booking &
|
||||
mongoose.Document &
|
||||
mongoose.SchemaTimestampsConfig
|
||||
|
||||
export interface BookingModel extends mongoose.Model<BookingDocument> {
|
||||
export type BookingModel = mongoose.Model<BookingDocument> & {
|
||||
findBookedDays(uuidsToIngore?: string[]): Promise<string[]>
|
||||
}
|
||||
|
||||
@@ -52,10 +51,11 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
required: true,
|
||||
get: dateFormatBackend,
|
||||
validate: {
|
||||
validator: function(v: Date): boolean {
|
||||
validator: function (v: Date): boolean {
|
||||
return v >= nowInTz()
|
||||
},
|
||||
message: (props: { value: Date }): string => `${props.value} is in the past`,
|
||||
message: (props: { value: Date }): string =>
|
||||
`${props.value} is in the past`,
|
||||
},
|
||||
},
|
||||
endDate: {
|
||||
@@ -63,17 +63,18 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
required: false,
|
||||
get: dateFormatBackend,
|
||||
validate: {
|
||||
validator: function(v: Date): boolean {
|
||||
validator: function (v: Date): boolean {
|
||||
return v >= nowInTz()
|
||||
},
|
||||
message: (props: { value: Date }): string => `${props.value} is in the past`,
|
||||
message: (props: { value: Date }): string =>
|
||||
`${props.value} is in the past`,
|
||||
},
|
||||
},
|
||||
days: {
|
||||
type: [String],
|
||||
required: true,
|
||||
validate: {
|
||||
validator: async function(days: string[]): Promise<boolean> {
|
||||
validator: async function (days: string[]): Promise<boolean> {
|
||||
const booking = this as Booking
|
||||
const uuid = booking.uuid && [booking.uuid]
|
||||
const bookedDays = await getBookedDays(uuid)
|
||||
@@ -105,7 +106,7 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
}
|
||||
)
|
||||
|
||||
BookingSchema.pre('validate', function(next: () => void): void {
|
||||
BookingSchema.pre('validate', function (next: () => void): void {
|
||||
const booking = this as BookingDocument
|
||||
booking.days = getDays({
|
||||
startDate: new Date(booking.startDate),
|
||||
@@ -114,7 +115,7 @@ BookingSchema.pre('validate', function(next: () => void): void {
|
||||
next()
|
||||
})
|
||||
|
||||
BookingSchema.static('findBookedDays', async function(
|
||||
BookingSchema.static('findBookedDays', async function (
|
||||
uuidsToIngore: string[] = []
|
||||
): Promise<string[]> {
|
||||
const model = this as BookingModel
|
||||
|
||||
Reference in New Issue
Block a user