mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import * as mongoose from 'mongoose'
|
|
|
|
import { getDays, dateFormatBackend } from '../helpers/date'
|
|
|
|
const BookingSchema = new mongoose.Schema(
|
|
{
|
|
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: ['requested', 'confirmed', 'rejected'],
|
|
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 })
|
|
})
|
|
|
|
export default mongoose.models.Booking ||
|
|
mongoose.model('Booking', BookingSchema)
|