ADD: isActive and Auto incremental id for numId
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const mongoose = require('mongoose')
|
const mongoose = require('mongoose')
|
||||||
const ObjectID = mongoose.Schema.Types.ObjectId
|
const ObjectID = mongoose.Schema.Types.ObjectId
|
||||||
|
const AutoIncrement = require('mongoose-sequence')(mongoose)
|
||||||
|
|
||||||
const belongingSchema = new mongoose.Schema(
|
const belongingSchema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
@@ -10,14 +11,14 @@ const belongingSchema = new mongoose.Schema(
|
|||||||
},
|
},
|
||||||
belongingCategory: {
|
belongingCategory: {
|
||||||
type: ObjectID,
|
type: ObjectID,
|
||||||
ref: 'Category'
|
ref: 'Category',
|
||||||
},
|
},
|
||||||
projectCode: {
|
projectCode: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
relatedProjects : [String],
|
relatedProjects: [String],
|
||||||
location: {
|
location: {
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -29,12 +30,27 @@ const belongingSchema = new mongoose.Schema(
|
|||||||
required: true,
|
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)
|
const Belonging = mongoose.model('Belonging', belongingSchema)
|
||||||
module.exports = Belonging
|
module.exports = Belonging
|
||||||
|
|||||||
Reference in New Issue
Block a user