const uniqueValidator = require('mongoose-unique-validator'); module.exports = mongoose => { var schema = mongoose.Schema( { // Basic Information vehicle_number: { type: Number, required: true, }, responsible_driver: String, responsible_driver_id: String, capacity: Number, mileage: Number, make: String, vehicle_model: String, year: String, vin: String, tag: { type: String, required: true }, gps_tag: String, ezpass: String, has_lift_equip: Boolean, fuel_type: String, title: String, title_other: String, // Compliance & Deadlines insurance_start_date: String, vehicle_registration_date: String, // Legacy fields (keeping for backward compatibility) insurance_expire_on: String, title_registration_on: String, emission_test_on: String, oil_change_mileage: Number, oil_change_date: String, // Check List checklist: [{ type: String }], // Additional Information note: String, // System fields 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; };