mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 14:37:13 +01:00
35 lines
837 B
JavaScript
35 lines
837 B
JavaScript
import { Schema } from 'mongoose'
|
|
|
|
import { getDays, dateFormat } from '../lib/dateHelper'
|
|
|
|
export const BookerSchema = new Schema(
|
|
{
|
|
name: { type: String, required: true },
|
|
email: { type: String, required: true, unique: true },
|
|
},
|
|
{ timestamps: true }
|
|
)
|
|
|
|
export const BookingSchema = new Schema(
|
|
{
|
|
booker: { type: Schema.Types.ObjectId, ref: 'Booker', required: true },
|
|
startDate: {
|
|
type: Date,
|
|
required: true,
|
|
get: dateFormat,
|
|
},
|
|
endDate: { type: Date, required: false, get: dateFormat },
|
|
status: {
|
|
type: String,
|
|
enum: ['requested', 'confirmed', 'rejected'],
|
|
required: true,
|
|
default: 'requested',
|
|
},
|
|
},
|
|
{ timestamps: true }
|
|
)
|
|
|
|
BookingSchema.virtual('days').get(function () {
|
|
return getDays({ startDate: this.startDate, endDate: this.endDate })
|
|
})
|