fix(auth/property): resolve auth token resolution, add property seeder
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 07:08:36 +03:30
parent 284594c782
commit 95c0532374
4 changed files with 168 additions and 3 deletions
+148
View File
@@ -0,0 +1,148 @@
const Property = require('./propertyModel')
const Land = require('./landModel')
const Building = require('./buildingModel')
const Category = require('../category/categoryModel')
const PropertyStatus = require('../propertyStatus/propertyStatusModel')
const chalk = require('chalk')
const runSeeder = async () => {
const buildingCategory = await Category.findOne({ englishName: 'Building' })
const lotCategory = await Category.findOne({ englishName: 'Lot' })
const availableStatus = await PropertyStatus.findOne({ englishName: 'available' })
const inReviewStatus = await PropertyStatus.findOne({ englishName: 'in_review' })
const reservedStatus = await PropertyStatus.findOne({ englishName: 'reserved' })
const sampleProperties = [
{
name: 'مجتمع اداری تجاری نگین الهیه',
propertyType: 'Building',
category: buildingCategory?._id,
status: availableStatus?._id,
nationalGeoCode: '537123395123439',
description: 'مجتمع اداری ۱۰ طبقه با دسترسی عالی به بزرگراه صدر و مترو',
dong: 6,
ownerName: 'شرکت سرمایه‌گذاری پارس',
registrationPlate: '۱۲۳۴/۵۶',
uniqueId: '140201123456789012',
serialNumber: 'A/987654',
zoningType: 'تجاری - اداری',
address: 'تهران، الهیه، خیابان فرشته، پلاک ۱۲',
postalCode: '1965834211',
location: {
type: 'Point',
coordinates: [51.4235, 35.7952], // [lng, lat]
},
tags: ['اداری', 'الهیه', 'مدرن', 'سند تک‌برگ'],
isActive: true,
},
{
name: 'زمین ویلایی شهرک غرب فاز ۴',
propertyType: 'Land',
category: lotCategory?._id,
status: availableStatus?._id,
nationalGeoCode: '536987394852139',
description: 'زمین دو کله با بر ۲۵ متر و دستور نقشه ۵ طبقه مسکونی',
dong: 6,
ownerName: 'محسن رضایی',
registrationPlate: '۴۵۶۷/۸۹',
uniqueId: '140202234567890123',
serialNumber: 'B/123456',
zoningType: 'مسکونی',
address: 'تهران، شهرک غرب، فاز ۴، خیابان فلامک شمالی',
postalCode: '1467893214',
location: {
type: 'Point',
coordinates: [51.3712, 35.7725],
},
tags: ['زمین', 'شهرک غرب', 'دو کله'],
isActive: true,
},
{
name: 'برج مسکونی یاس نیاوران',
propertyType: 'Building',
category: buildingCategory?._id,
status: reservedStatus?._id || availableStatus?._id,
nationalGeoCode: '539145395412039',
description: 'واحد ۳۰۰ متری طبقه ۸ با ویوی ابدی کاخ نیاوران و ۳ پارکینگ سندی',
dong: 6,
ownerName: 'سارا صادقی',
registrationPlate: '۷۸۹۰/۱۲',
uniqueId: '140203345678901234',
serialNumber: 'C/654321',
zoningType: 'مسکونی',
address: 'تهران، نیاوران، خیابان باهنر، کوچه یاس',
postalCode: '1978945612',
location: {
type: 'Point',
coordinates: [51.4678, 35.8156],
},
tags: ['لوکس', 'نیاوران', 'پنت‌هاوس'],
isActive: true,
},
{
name: 'باغ ویلای قصرالدشت شیراز',
propertyType: 'Land',
category: lotCategory?._id,
status: availableStatus?._id,
nationalGeoCode: '645123328456139',
description: 'باغ ۲۰۰۰ متری با درختان کهنسال و عمارت دوبلکس ۴۰۰ متری',
dong: 6,
ownerName: 'علیرضا زندی',
registrationPlate: '۳۲۱۴/۵۶',
uniqueId: '140204456789012345',
serialNumber: 'D/789123',
zoningType: 'باغ ویلا',
address: 'شیراز، قصرالدشت، خیابان وکلا، کوچه ۱۲',
postalCode: '7198765432',
location: {
type: 'Point',
coordinates: [52.4823, 29.6412],
},
tags: ['شیراز', 'باغ', 'قصرالدشت'],
isActive: true,
},
{
name: 'ملک تجاری چهارباغ عباسی اصفهان',
propertyType: 'Building',
category: buildingCategory?._id,
status: inReviewStatus?._id || availableStatus?._id,
nationalGeoCode: '584123361456239',
description: 'مغازه تجاری دو دهنه بر خیابان اصلی چهارباغ با سند شش دانگ ملکیت',
dong: 6,
ownerName: 'محمد مهدی اصفهانی',
registrationPlate: '۹۶۳۲/۱۴',
uniqueId: '140205567890123456',
serialNumber: 'E/456789',
zoningType: 'تجاری',
address: 'اصفهان، خیابان چهارباغ عباسی، جنب سینما سپاهان',
postalCode: '8145678901',
location: {
type: 'Point',
coordinates: [51.6685, 32.6546],
},
tags: ['اصفهان', 'تجاری', 'چهارباغ'],
isActive: true,
},
]
await Property.deleteMany({})
console.log(chalk.red('Deleted all property records.'))
for (const propData of sampleProperties) {
if (propData.propertyType === 'Building') {
await Building.create(propData)
} else if (propData.propertyType === 'Land') {
await Land.create(propData)
} else {
await Property.create(propData)
}
}
console.log(
chalk.green.bold(
`PROPERTIES: Created ${sampleProperties.length} sample property(ies)`
)
)
}
module.exports = { runSeeder }
+10
View File
@@ -26,6 +26,11 @@ exports.loginUser = catchAsync(async (req, res, next) => {
maxAge: maxAge * 1000, maxAge: maxAge * 1000,
path: '/', path: '/',
}) })
res.cookie('bm-token', token, {
httpOnly: false,
maxAge: maxAge * 1000,
path: '/',
})
res.status(200).json({ res.status(200).json({
status: 'success', status: 'success',
@@ -39,6 +44,11 @@ exports.logoutUser = catchAsync(async (req, res, next) => {
maxAge: 0, maxAge: 0,
path: '/', path: '/',
}) })
res.cookie('bm-token', '', {
httpOnly: false,
maxAge: 0,
path: '/',
})
res.status(200).json({ res.status(200).json({
status: 'success', status: 'success',
+8 -3
View File
@@ -8,10 +8,15 @@ exports.loginProtect = async (req, res, next) => {
let token let token
token = req.cookies['bm-token']
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer')) { if (req.headers.authorization && req.headers.authorization.startsWith('Bearer')) {
token = req.headers.authorization.split(' ')[1] const headerToken = req.headers.authorization.split(' ')[1]
if (headerToken && headerToken !== 'undefined' && headerToken !== 'null' && headerToken.trim() !== '') {
token = headerToken.trim()
}
}
if (!token && req.cookies) {
token = req.cookies['bm-token'] || req.cookies['belonging_token'] || req.cookies['jwt']
} }
if (!token) { if (!token) {
+2
View File
@@ -3,6 +3,7 @@ const categorySeeder = require('../components/category/categorySeeder')
const roleSeeder = require('../components/role/roleSeeder') const roleSeeder = require('../components/role/roleSeeder')
const featureSeeder = require('../components/feature/featureSeeder') const featureSeeder = require('../components/feature/featureSeeder')
const propertyStatusSeeder = require('../components/propertyStatus/propertyStatusSeeder') const propertyStatusSeeder = require('../components/propertyStatus/propertyStatusSeeder')
const propertySeeder = require('../components/property/propertySeeder')
const propertyService = require('../components/property/propertyService') const propertyService = require('../components/property/propertyService')
const transactionService = require('../components/transaction/transactionService') const transactionService = require('../components/transaction/transactionService')
@@ -12,6 +13,7 @@ module.exports.run = async () => {
await roleSeeder.runSeeder() await roleSeeder.runSeeder()
await featureSeeder.runSeeder() await featureSeeder.runSeeder()
await propertyStatusSeeder.runSeeder() await propertyStatusSeeder.runSeeder()
await propertySeeder.runSeeder()
try { try {
await propertyService.indexAllProperties() await propertyService.indexAllProperties()