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
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
||||
const propertyService = require('./propertyService')
|
||||
const { eventEmitter } = require('../../events/eventEmitter')
|
||||
|
||||
exports.searchProperties = catchAsync(async (req, res, next) => {
|
||||
const { facets, belongings, totalCount, pagesCount } = await propertyService.searchProperties(req.query)
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
facets,
|
||||
properties: belongings,
|
||||
totalCount,
|
||||
pagesCount,
|
||||
})
|
||||
})
|
||||
|
||||
exports.indexAllProperties = catchAsync(async (req, res, next) => {
|
||||
const { indexedCount } = await propertyService.indexAllProperties()
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
indexedCount,
|
||||
})
|
||||
})
|
||||
|
||||
exports.indexOneProperty = catchAsync(async (req, res, next) => {
|
||||
await propertyService.indexOneProperty(req.params.propertyId)
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
})
|
||||
})
|
||||
|
||||
exports.getAllProperties = catchAsync(async (req, res, next) => {
|
||||
const properties = await propertyService.getAllProperties()
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
results: properties.length,
|
||||
data: properties,
|
||||
})
|
||||
})
|
||||
|
||||
exports.createProperty = catchAsync(async (req, res, next) => {
|
||||
const property = await propertyService.createProperty(req.body)
|
||||
eventEmitter.emit('createProperty', property)
|
||||
|
||||
res.status(201).json({
|
||||
status: 'success',
|
||||
data: property,
|
||||
})
|
||||
})
|
||||
|
||||
exports.getProperty = catchAsync(async (req, res, next) => {
|
||||
const property = await propertyService.getProperty(req.params.propertyId)
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: property,
|
||||
})
|
||||
})
|
||||
|
||||
exports.updateProperty = catchAsync(async (req, res, next) => {
|
||||
const property = await propertyService.updateProperty(req.params.propertyId, req.body)
|
||||
await propertyService.indexAllProperties()
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: property,
|
||||
})
|
||||
})
|
||||
|
||||
exports.deleteProperty = catchAsync(async (req, res, next) => {
|
||||
await propertyService.deleteProperty(req.params.propertyId)
|
||||
// eventEmitter.emit('deleteProperty')
|
||||
|
||||
res.status(204).json({
|
||||
status: 'success',
|
||||
data: null,
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user