ADD: Events

ADD: Index One Belonging
ADD: Belonging Code
This commit is contained in:
2025-06-04 16:07:45 +03:30
parent 98044a18f2
commit de60d4f163
9 changed files with 142 additions and 7 deletions
@@ -1,5 +1,6 @@
const catchAsync = require('../../globalErrorHandler/catchAsync')
const belongingService = require('./belongingService')
const { eventEmitter } = require('../../events/eventEmitter')
exports.searchBelongings = catchAsync(async (req, res, next) => {
const { facets, belongings, totalCount, pagesCount } = await belongingService.searchBelongings(req.query)
@@ -22,6 +23,14 @@ exports.indexAllBelongings = catchAsync(async (req, res, next) => {
})
})
exports.indexOneBelonging = catchAsync(async (req, res, next) => {
await belongingService.indexOneBelonging()
res.status(200).json({
status: 'success',
})
})
exports.getAllBelongings = catchAsync(async (req, res, next) => {
const belongings = await belongingService.getAllBelongings()
@@ -34,6 +43,7 @@ exports.getAllBelongings = catchAsync(async (req, res, next) => {
exports.createBelonging = catchAsync(async (req, res, next) => {
const belonging = await belongingService.createBelonging(req.body)
eventEmitter.emit('createBelonging', belonging)
res.status(201).json({
status: 'success',
@@ -52,6 +62,7 @@ exports.getBelonging = catchAsync(async (req, res, next) => {
exports.updateBelonging = catchAsync(async (req, res, next) => {
const belonging = await belongingService.updateBelonging(req.params.belongingId, req.body)
await belongingService.indexAllBelongings()
res.status(200).json({
status: 'success',
@@ -61,6 +72,7 @@ exports.updateBelonging = catchAsync(async (req, res, next) => {
exports.deleteBelonging = catchAsync(async (req, res, next) => {
await belongingService.deleteBelonging(req.params.belongingId)
// eventEmitter.emit('deleteBelonging')
res.status(204).json({
status: 'success',