Skip to content

Instantly share code, notes, and snippets.

@fayimora
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fayimora/94213d1322ad4a8d66bd to your computer and use it in GitHub Desktop.
Save fayimora/94213d1322ad4a8d66bd to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var PriceDetailsSchema = new Schema({
minimum: Number,
cancellationFee: Number,
costPerDistance: Number
});
mongoose.model('PriceDetails', PriceDetailsSchema);
var VehicleSchema = new Schema({
make: String,
model: String,
licensePlate: String,
imageURL: String,
max_parcel_weight: String,
max_parcel_size: String,
priceDetails: {type: Schema.ObjectId, ref: 'PriceDetails', required: true},
createdAt: Date,
updatedAt: Date
});
VehicleSchema.pre('save', function(next) {
var now = new Date();
this.updatedAt = now;
if(!this.createdAt) {
this.createdAt = now;
}
next();
});
module.exports = mongoose.model('Vehicle', VehicleSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment