mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-16 13:14:35 +00:00
Initial commit 🚀
This commit is contained in:
38
4-natours/after-section-14/models/bookingModel.js
Normal file
38
4-natours/after-section-14/models/bookingModel.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const bookingSchema = new mongoose.Schema({
|
||||
tour: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: 'Tour',
|
||||
required: [true, 'Booking must belong to a Tour!']
|
||||
},
|
||||
user: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: [true, 'Booking must belong to a User!']
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
require: [true, 'Booking must have a price.']
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now()
|
||||
},
|
||||
paid: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
});
|
||||
|
||||
bookingSchema.pre(/^find/, function(next) {
|
||||
this.populate('user').populate({
|
||||
path: 'tour',
|
||||
select: 'name'
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
const Booking = mongoose.model('Booking', bookingSchema);
|
||||
|
||||
module.exports = Booking;
|
||||
Reference in New Issue
Block a user