Property system: - Rename belonging → property throughout (model, controller, routes, service) - Add property sub-models: buildingModel, landModel, belongingModel - Add property lifecycle events: createProperty, deleteProperty - Add propertyStatus component (model, controller, routes, service, seeder) - Add commodity and commodityTransaction model stubs Infrastructure: - Update transactionModel and transactionService - Update events/index.js for new property events - Update seeder (seederDBConnection, seederRunner) - Update typesense client configuration - Update upload utilities (bucket, minio) - Update featureModel and featureSeeder - Update categorySeeder - Update TsApiFeatures utility - Remove docker-compose.yml (moved to root) - Remove legacy belonging component files
84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
const mongoose = require('mongoose')
|
|
const ObjectID = mongoose.Schema.Types.ObjectId
|
|
const AutoIncrement = require('mongoose-sequence')(mongoose)
|
|
const { getMultipleSignedUrls, getSignedUrl } = require('../file/fileService')
|
|
|
|
const belongingSchema = new mongoose.Schema(
|
|
{
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
unique: true,
|
|
},
|
|
// belongingCode: {
|
|
// type: Number,
|
|
// unique: true,
|
|
// },
|
|
category: {
|
|
type: ObjectID,
|
|
ref: 'Category',
|
|
},
|
|
unit: {
|
|
type: String,
|
|
},
|
|
description: String,
|
|
relatedProjects: [String],
|
|
location: {
|
|
type: {
|
|
type: String,
|
|
enum: ['Point'], // GeoJSON type
|
|
required: false,
|
|
},
|
|
coordinates: {
|
|
type: [Number], // Array of numbers: [longitude, latitude]
|
|
required: false,
|
|
},
|
|
},
|
|
documentUrls: [String],
|
|
mainImageUrls: [String],
|
|
nationalGeoCode: String,
|
|
tags: [String],
|
|
status: {
|
|
type: ObjectID,
|
|
ref: 'BelongingStatus',
|
|
},
|
|
isActive: {
|
|
type: Boolean,
|
|
default: true,
|
|
select: false,
|
|
},
|
|
features: [
|
|
{
|
|
definition: {
|
|
type: ObjectID,
|
|
ref: 'Feature',
|
|
required: true,
|
|
},
|
|
value: mongoose.Schema.Types.Mixed,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
toJSON: { virtuals: true },
|
|
toObject: { virtuals: true },
|
|
timestamps: true,
|
|
}
|
|
)
|
|
|
|
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
|
|
|
|
belongingSchema.methods.getDocumentsSignedUrls = function () {
|
|
return getMultipleSignedUrls(this.documentUrls, 'belonging-documents')
|
|
}
|
|
|
|
belongingSchema.methods.getMainImagedSignedUrl = function () {
|
|
return getMultipleSignedUrls(this.mainImageUrls, 'belonging-images')
|
|
}
|
|
|
|
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
|
|
|
|
// belongingSchema.plugin(AutoIncrement, { inc_field: 'numId' })
|
|
|
|
const Belonging = mongoose.model('Belonging', belongingSchema)
|
|
module.exports = Belonging
|