ADD: isActive and Auto incremental id for numId

This commit is contained in:
MohammadHMazarei
2024-12-29 23:07:30 +03:30
parent 82b384401c
commit a63c44a7bd
+20 -4
View File
@@ -1,5 +1,6 @@
const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const AutoIncrement = require('mongoose-sequence')(mongoose)
const belongingSchema = new mongoose.Schema(
{
@@ -10,7 +11,7 @@ const belongingSchema = new mongoose.Schema(
},
belongingCategory: {
type: ObjectID,
ref: 'Category'
ref: 'Category',
},
projectCode: {
type: String,
@@ -29,12 +30,27 @@ const belongingSchema = new mongoose.Schema(
required: true,
},
},
documents: [String]
documents: [String],
numId: {
type: Number,
unique: true,
},
{ timestamps: true }
isActive: {
type: Boolean,
default: true,
select: false,
},
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
timestamps: true,
}
)
belongingSchema.index({ location: '2dsphere' }); // Enable geospatial queries
belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' })
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
const Belonging = mongoose.model('Belonging', belongingSchema)
module.exports = Belonging