address breaking changes

This commit is contained in:
Thomas Ruoff
2022-03-14 22:35:30 +01:00
committed by Thomas Ruoff
parent 8222e04880
commit ef7f80fd92
10 changed files with 41 additions and 46 deletions

View File

@@ -16,8 +16,10 @@ export type Booking = {
zip: string
city: string
bill?: Bill
startDate: string
endDate: string
start: string
startDate: Date
endDate: Date
end: string
status?: BOOKING_STATUS
purpose?: string
org?: string
@@ -56,26 +58,10 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
startDate: {
type: Date,
required: true,
get: dateFormatBackend,
validate: {
validator: function (v: Date): boolean {
return v >= nowInTz()
},
message: (props: { value: Date }): string =>
`${props.value} is in the past`,
},
},
endDate: {
type: Date,
required: false,
get: dateFormatBackend,
validate: {
validator: function (v: Date): boolean {
return v >= nowInTz()
},
message: (props: { value: Date }): string =>
`${props.value} is in the past`,
},
},
days: {
type: [String],
@@ -100,7 +86,7 @@ const BookingSchema = new mongoose.Schema<BookingDocument>(
type: String,
enum: Object.values(BOOKING_STATUS),
required: true,
default: 'requested',
default: BOOKING_STATUS.REQUESTED,
},
purpose: { type: String, required: false },
org: { type: String, required: false },
@@ -114,6 +100,16 @@ 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({

View File

@@ -7,18 +7,12 @@ let connectedPromise: Promise<mongoose.Mongoose>
export const MONGO_URI = process.env.MONGO_URI
export const MONGODB_OPTIONS = {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
}
export function connect(): Promise<mongoose.Mongoose> {
if (connectedPromise) {
return connectedPromise
}
connectedPromise = mongoose.connect(process.env.MONGO_URI, MONGODB_OPTIONS)
connectedPromise = mongoose.connect(process.env.MONGO_URI)
return connectedPromise
}