mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
put models in file not schema
This commit is contained in:
41
db/booking.js
Normal file
41
db/booking.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import * as mongoose from 'mongoose'
|
||||
|
||||
import { getDays, dateFormat } from '../helpers/date'
|
||||
|
||||
const BookingSchema = new mongoose.Schema(
|
||||
{
|
||||
booker: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Booker',
|
||||
required: true,
|
||||
},
|
||||
startDate: {
|
||||
type: Date,
|
||||
required: true,
|
||||
get: dateFormat,
|
||||
min: new Date(),
|
||||
},
|
||||
endDate: { type: Date, required: false, get: dateFormat, 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)
|
||||
Reference in New Issue
Block a user