Spaces:
Runtime error
Runtime error
| const { mongoose, baseSchemaOptions } = require('./base'); | |
| const GatePassSchema = new mongoose.Schema({ | |
| employee_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Employee', required: true }, | |
| issue_date: { type: Date, required: true }, | |
| expiry_date: { type: Date, required: true }, | |
| fee_paid: { type: Boolean, default: false }, | |
| fee_amount: { type: Number, default: 100 }, | |
| barcode: { type: String, required: true, unique: true }, | |
| status: { type: String, enum: ['Pending_Fee', 'Active', 'Expired'], default: 'Pending_Fee' }, | |
| issued_by: { type: mongoose.Schema.Types.ObjectId, ref: 'User', default: null } | |
| }, baseSchemaOptions()); | |
| GatePassSchema.pre('validate', function setExpiry(next) { | |
| if (this.issue_date) { | |
| const dt = new Date(this.issue_date); | |
| dt.setDate(dt.getDate() + 90); | |
| this.expiry_date = dt; | |
| } | |
| next(); | |
| }); | |
| GatePassSchema.index({ employee_id: 1, issue_date: 1 }, { unique: true }); | |
| GatePassSchema.index({ expiry_date: 1 }); | |
| module.exports = mongoose.model('GatePass', GatePassSchema); | |