new procurement
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const mongoose = require('mongoose')
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const productSchema = new mongoose.Schema({
|
||||
name: {
|
||||
@@ -22,25 +22,36 @@ const productSchema = new mongoose.Schema({
|
||||
},
|
||||
productUrl: String,
|
||||
companyId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Company',
|
||||
required: true
|
||||
type: String,
|
||||
required: true,
|
||||
index: true
|
||||
},
|
||||
price: String,
|
||||
unit: String,
|
||||
minOrder: String,
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
default: Date.now,
|
||||
index: true
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Индекс для поиска
|
||||
productSchema.index({ companyId: 1, type: 1 })
|
||||
productSchema.index({ name: 'text', description: 'text' })
|
||||
productSchema.index({ companyId: 1, type: 1 });
|
||||
productSchema.index({ name: 'text', description: 'text' });
|
||||
|
||||
module.exports = mongoose.model('Product', productSchema)
|
||||
// Transform _id to id in JSON output
|
||||
productSchema.set('toJSON', {
|
||||
transform: (doc, ret) => {
|
||||
ret.id = ret._id;
|
||||
delete ret._id;
|
||||
delete ret.__v;
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Product', productSchema);
|
||||
|
||||
Reference in New Issue
Block a user