Files
mbmanager-api/components/belonging/belongingModel.js
T
kavehhn 465b678357 FIX: UserSeeder
ADD: Get-Self endpoint for users
ADD: Category and Role Seeder
FIX: Login Check Bug
ADD: Extra fields for documents and images in belonging model
ADD: localhost:5173 to cors
ADD: SuperAdmin ID to env
2025-01-03 17:45:09 +03:30

59 lines
1.5 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',
},
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