feat(property): convert registrationDate to Date object and add Jalali utilities
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 06:45:50 +03:30
parent 982b9e759f
commit 8bdd5af719
3 changed files with 185 additions and 1 deletions
+10
View File
@@ -5,6 +5,7 @@ const AppError = require('../../globalErrorHandler/AppError')
const { client } = require('../../setup/typesense')
const TsApiFeatures = require('../../utils/TsApiFeatures')
const { moveFromTempToMain, getSignedUrl } = require('../file/fileService')
const { normalizeToDate } = require('../../utils/jalali')
const getAllProperties = async () => {
return Property.find({}, null, null).populate('category').populate('status')
@@ -18,6 +19,10 @@ const createProperty = async (data) => {
data.documentUrls = await moveFromTempToMain(data.documentUrls, 'documents')
}
if (data.registrationDate !== undefined) {
data.registrationDate = normalizeToDate(data.registrationDate)
}
if (data.propertyType === 'Land' || data.propertyType === 'زمین') {
return Land.create(data)
} else if (data.propertyType === 'Building' || data.propertyType === 'ساختمان') {
@@ -52,6 +57,10 @@ const updateProperty = async (propertyId, data) => {
data.documentUrls = await moveFromTempToMain(data.documentUrls, 'documents')
}
if (data.registrationDate !== undefined) {
data.registrationDate = normalizeToDate(data.registrationDate)
}
const property = await Property.findOneAndUpdate({ _id: propertyId }, data, { new: true })
if (!property) {
@@ -180,6 +189,7 @@ const searchPropertiesMongo = async (inputQuery = {}) => {
registrationPlate: prop.registrationPlate || '',
uniqueId: prop.uniqueId || '',
serialNumber: prop.serialNumber || '',
registrationDate: prop.registrationDate,
coordinates: prop.location?.coordinates || [0, 0],
location: prop.location,
createdAt: Math.floor(new Date(prop.createdAt || Date.now()).getTime() / 1000),