emm - use string instead of date for start/endDate

This commit is contained in:
Thomas Ruoff
2022-03-30 23:56:08 +02:00
parent 9f45eab6e7
commit c65d8df853
8 changed files with 13652 additions and 878 deletions

View File

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