worldshine-redesign/app/models/vehicle.model.js
2025-04-14 16:29:36 -04:00

40 lines
1.1 KiB
JavaScript

const uniqueValidator = require('mongoose-unique-validator');
module.exports = mongoose => {
var schema = mongoose.Schema(
{
vehicle_number: {
type: Number,
required: true,
},
tag: {
type: String,
required: true
},
ezpass: {
type: String,
},
gps_tag: {
type: String,
},
mileage: Number,
capacity: Number,
make: String,
vehicle_model: String,
year: String,
checklist: [{
type: String
}],
status: String,
site: Number
},
{ collection: 'vehicle', timestamps: true }
);
schema.method("toJSON", function() {
const { __v, _id, ...object } = this.toObject();
object.id = _id;
return object;
});
schema.index({tag: 1, site:1}, {unique: true});
const Vehicle = mongoose.model("vehicle", schema);
return Vehicle;
};