mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
rename js/x ts/x
This commit is contained in:
committed by
Thomas Ruoff
parent
9853e31201
commit
be1e22460d
57
db/booking.ts
Normal file
57
db/booking.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import * as mongoose from 'mongoose'
|
||||
|
||||
import { getDays, dateFormatBackend } from '../helpers/date'
|
||||
|
||||
import { BOOKING_STATUS } from './bookingStatus'
|
||||
|
||||
const BookingSchema = new mongoose.Schema(
|
||||
{
|
||||
// need a seperate uuid to be able to target a booking anonimously
|
||||
uuid: {
|
||||
type: String,
|
||||
default: uuidv4,
|
||||
index: true,
|
||||
},
|
||||
booker: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Booker',
|
||||
required: true,
|
||||
},
|
||||
startDate: {
|
||||
type: Date,
|
||||
required: true,
|
||||
get: dateFormatBackend,
|
||||
min: new Date(),
|
||||
},
|
||||
endDate: {
|
||||
type: Date,
|
||||
required: false,
|
||||
get: dateFormatBackend,
|
||||
min: new Date(),
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
enum: Object.values(BOOKING_STATUS),
|
||||
required: true,
|
||||
default: 'requested',
|
||||
},
|
||||
purpose: { type: String, required: false },
|
||||
org: { type: String, required: false },
|
||||
destination: { type: String, required: false },
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true, getters: true },
|
||||
toObject: { virtuals: true, getters: true },
|
||||
}
|
||||
)
|
||||
|
||||
BookingSchema.virtual('days').get(function () {
|
||||
return getDays({ startDate: this.startDate, endDate: this.endDate })
|
||||
})
|
||||
|
||||
BookingSchema.virtual('hash').get(function () {})
|
||||
|
||||
export default mongoose.models.Booking ||
|
||||
mongoose.model('Booking', BookingSchema)
|
||||
Reference in New Issue
Block a user