Files
mbmanager-api/components/belonging/belongingModel.js
T
2025-04-17 10:54:50 +03:30

63 lines
1.6 KiB
JavaScript

const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const AutoIncrement = require('mongoose-sequence')(mongoose)
const belongingSchema = new mongoose.Schema(
{
belongingCode: {
type: String,
required: true,
unique: true,
},
category: {
type: ObjectID,
ref: 'Category',
},
unit: {
type: String,
required: true,
},
description: String,
relatedProjects: [String],
location: {
type: {
type: String,
enum: ['Point'], // GeoJSON type
required: true,
},
coordinates: {
type: [Number], // Array of numbers: [longitude, latitude]
required: true,
},
},
documentNames: [String],
documentUrls: [String],
imageNames: [String],
imageUrls: [String],
mainImageUrl: String,
mainImageName: String,
numId: {
type: Number,
unique: true,
},
tags: [String],
isActive: {
type: Boolean,
default: true,
select: false,
},
},
{
toJSON: { virtuals: true },
toObject: { virtuals: true },
timestamps: true,
}
)
belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' })
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
const Belonging = mongoose.model('Belonging', belongingSchema)
module.exports = Belonging