const { Schema, model } = require('mongoose') const { orderStatus } = require('./const') const schema = new Schema({ phone: { type: String, required: true }, carNumber: { type: String, required: true }, carBody: { type: Number, required: true }, carColor: String, startWashTime: { type: Date, required: true }, endWashTime: { type: Date, required: true }, location: { type: String, required: true }, status: { type: String, required: true, enum: Object.values(orderStatus) }, master: { type: Schema.Types.ObjectId, ref: 'dry-wash-master' }, notes: String, created: { type: Date, default: () => new Date().toISOString(), }, updated: { type: Date, default: () => new Date().toISOString(), }, }) schema.set('toJSON', { virtuals: true, versionKey: false, transform(_doc, ret) { delete ret._id } }) schema.virtual('id').get(function () { return this._id.toHexString() }) exports.OrderModel = model('dry-wash-order', schema)