mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
emm - use string instead of date for start/endDate
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as mongoose from 'mongoose'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { dateFormatBackend, getDays, nowInTz } from '../helpers/date'
|
||||
import { dateFormatBackend, getDays, nowInTz, dateParseBackend } from '../helpers/date'
|
||||
import { createCalendarEvent, deleteCalendarEvent } from '../lib/googlecalendar'
|
||||
|
||||
import { Bill } from './bill'
|
||||
@@ -17,11 +17,9 @@ export type Booking = {
|
||||
city: string
|
||||
bill?: Bill
|
||||
// format YYYY-MM-DD
|
||||
start: string,
|
||||
startDate: Date
|
||||
startDate: string,
|
||||
// format YYYY-MM-DD
|
||||
end: string
|
||||
endDate: Date
|
||||
endDate: string,
|
||||
status?: BOOKING_STATUS
|
||||
purpose?: string
|
||||
org?: string
|
||||
@@ -58,12 +56,18 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
required: false,
|
||||
},
|
||||
startDate: {
|
||||
type: Date,
|
||||
type: String,
|
||||
required: true,
|
||||
validator: function (value: string): boolean {
|
||||
return !!dateParseBackend(value);
|
||||
},
|
||||
},
|
||||
endDate: {
|
||||
type: Date,
|
||||
required: false,
|
||||
type: String,
|
||||
required: true,
|
||||
validator: function (value: string): boolean {
|
||||
return !!dateParseBackend(value);
|
||||
},
|
||||
},
|
||||
days: {
|
||||
type: [String],
|
||||
@@ -102,16 +106,6 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
|
||||
}
|
||||
)
|
||||
|
||||
BookingSchema.virtual('start').get(function (): string {
|
||||
const booking = this as BookingDocument
|
||||
return dateFormatBackend(booking.startDate)
|
||||
})
|
||||
|
||||
BookingSchema.virtual('end').get(function (): string {
|
||||
const booking = this as BookingDocument
|
||||
return dateFormatBackend(booking.endDate)
|
||||
})
|
||||
|
||||
BookingSchema.pre('validate', function (next: () => void): void {
|
||||
const booking = this as BookingDocument
|
||||
booking.days = getDays({
|
||||
|
||||
Reference in New Issue
Block a user