Files
mbmanager-api/components/property/propertyModel.js
T
2026-08-19 06:30:00 +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, 'documents')
}
propertySchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageUrls, 'properties')
}
propertySchema.index({ location: '2dsphere' })
const Property = mongoose.model('Property', propertySchema)
module.exports = Property