Files
mbmanager-api/components/belonging/belongingModel.js
T
2024-12-22 16:52:30 +03:30

41 lines
1.0 KiB
JavaScript

const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const belongingSchema = new mongoose.Schema(
{
belongingCode: {
type: String,
required: true,
unique: true,
},
belongingCategory: {
type: ObjectID,
ref: 'Category'
},
projectCode: {
type: String,
required: true,
default: false,
},
relatedProjects : [String],
location: {
type: {
type: String,
enum: ['Point'], // GeoJSON type
required: true,
},
coordinates: {
type: [Number], // Array of numbers: [longitude, latitude]
required: true,
},
},
documents: [String]
},
{ timestamps: true }
)
belongingSchema.index({ location: '2dsphere' }); // Enable geospatial queries
const Belonging = mongoose.model('Belonging', belongingSchema)
module.exports = Belonging