ADD: isActive and Auto incremental id for numId
This commit is contained in:
@@ -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,14 +11,14 @@ const belongingSchema = new mongoose.Schema(
|
||||
},
|
||||
belongingCategory: {
|
||||
type: ObjectID,
|
||||
ref: 'Category'
|
||||
ref: 'Category',
|
||||
},
|
||||
projectCode: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
relatedProjects : [String],
|
||||
relatedProjects: [String],
|
||||
location: {
|
||||
type: {
|
||||
type: String,
|
||||
@@ -29,12 +30,27 @@ const belongingSchema = new mongoose.Schema(
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
documents: [String]
|
||||
documents: [String],
|
||||
numId: {
|
||||
type: Number,
|
||||
unique: true,
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
select: false,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
{
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user