Files
mbmanager-api/components/property/propertyModel.js
T
kavehhn ca911b97a0 REFACTOR: Belonging → Property system migration + utilities update
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
2026-08-11 20:35:47 +03:30

131 lines
3.7 KiB
JavaScript

const mongoose = require('mongoose')
const ObjectID = mongoose.Schema.Types.ObjectId
const AutoIncrement = require('mongoose-sequence')(mongoose)
const { getMultipleSignedUrls } = require('../file/fileService')
const propertySchemaOptions = {
discriminatorKey: 'propertyType',
toJSON: { virtuals: true },
toObject: { virtuals: true },
timestamps: true,
}
const propertySchema = new mongoose.Schema(
{
name: {
type: String,
required: false, // Auto-generated: ownerName + mainNumber/subNumber
},
category: {
type: ObjectID,
ref: 'Category',
},
description: String,
relatedProjects: [String],
location: {
type: {
type: String,
enum: ['Point'],
required: false,
},
coordinates: {
type: [Number], // [longitude, latitude]
required: false,
},
},
documentUrls: {
type: [String],
default: [],
},
mainImageUrls: [String],
nationalGeoCode: {
type: String,
required: true, // شناسه ملی جغرافیایی الزامی است
},
tags: [String],
status: {
type: ObjectID,
ref: 'PropertyStatus',
},
isActive: {
type: Boolean,
default: true,
select: false,
},
// Title Deed General & Administrative (شناسه و اداره ثبت)
uniqueId: String, // شناسه یکتا سند مالکیت (۱۸ رقمی)
serialNumber: String, // شماره سریال چاپی سند
provinceRegistry: String,
localRegistryOffice: String,
registrationDate: String, // تاریخ ثبت سند
// Owner Specifications (مشخصات مالک)
ownerName: String,
fatherName: String,
idCardNumber: String,
nationalId: String,
issuePlace: String,
birthDate: String,
nationality: {
type: String,
default: 'ایران',
},
ownershipDocs: String,
// Property Specifications (مشخصات ملک)
registrationPlate: String,
mainNumber: String,
subNumber: String,
separatedFrom: String,
plotNumber: String,
registrationSection: String,
district: String,
blockNumber: String,
sideDirection: String,
floor: String,
zoningType: String,
specialStatus: String,
documentType: String,
address: String,
postalCode: String,
propertyBoundaries: String,
restrictions: String,
// دانگ: سهم ملک از ۶ دانگ (۱ تا ۶)
dong: {
type: Number,
min: 1,
max: 6,
default: 6,
},
features: [
{
definition: {
type: ObjectID,
ref: 'Feature',
required: true,
},
value: mongoose.Schema.Types.Mixed,
},
],
},
propertySchemaOptions
)
propertySchema.plugin(AutoIncrement, { inc_field: 'propertyCode' })
propertySchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentUrls, 'property-documents')
}
propertySchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageUrls, 'property-images')
}
propertySchema.index({ location: '2dsphere' })
const Property = mongoose.model('Property', propertySchema)
module.exports = Property