import { v4 as uuidv4 } from 'uuid' import * as mongoose from 'mongoose' import { getDays, dateFormatBackend } from '../helpers/date' const BookingSchema = new mongoose.Schema( { _id: { type: String, default: uuidv4, }, 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 }) }) BookingSchema.virtual('hash').get(function () {}) export default mongoose.models.Booking || mongoose.model('Booking', BookingSchema)