Files
mbmanager-api/components/belonging/belongingController.js
T
kavehhn 1021774c89 ADD: Server urls
ADD: SearchBelongings function
REMOVE: API from docker compose (run it manually)
ADD: Required packages
REMOVE: Redundant import from TsApiFeatures
2025-01-02 16:45:16 +03:30

68 lines
1.8 KiB
JavaScript

const catchAsync = require('../../globalErrorHandler/catchAsync')
const belongingService = require('./belongingService')
exports.searchBelongings = catchAsync(async (req, res, next) => {
const {facets, belongings, totalCount, pagesCount} = await belongingService.searchBelongings()
res.status(200).json({
status: 'success',
facets, belongings, totalCount, pagesCount
})
})
exports.indexAllBelongings = catchAsync(async (req, res, next) => {
const { indexedCount } = await belongingService.indexAllBelongings()
res.status(200).json({
status: 'success',
indexedCount
})
})
exports.getAllBelongings = catchAsync(async (req, res, next) => {
const belongings = await belongingService.getAllBelongings()
res.status(200).json({
status: 'success',
results: belongings.length,
data: belongings,
})
})
exports.createBelonging = catchAsync(async (req, res, next) => {
const belonging = await belongingService.createBelonging(req.body)
res.status(201).json({
status: 'success',
data: belonging,
})
})
exports.getBelonging = catchAsync(async (req, res, next) => {
const belonging = await belongingService.getBelonging(req.params.belongingId)
res.status(200).json({
status: 'success',
data: belonging,
})
})
exports.updateBelonging = catchAsync(async (req, res, next) => {
const belonging = await belongingService.updateBelonging(req.params.belongingId, req.body)
res.status(200).json({
status: 'success',
data: belonging,
})
})
exports.deleteBelonging = catchAsync(async (req, res, next) => {
await belongingService.deleteBelonging(req.params.belongingId)
res.status(204).json({
status: 'success',
data: null,
})
})