58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const categoryService = require('./categoryService')
|
|
|
|
exports.getCategoryTree = catchAsync(async (req, res, next) => {
|
|
const categoryTree = await categoryService.getCategoryTree()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: categoryTree,
|
|
})
|
|
})
|
|
|
|
exports.getAllCategories = catchAsync(async (req, res, next) => {
|
|
const categories = await categoryService.getAllCategories()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: categories.length,
|
|
data: categories,
|
|
})
|
|
})
|
|
|
|
exports.createCategory = catchAsync(async (req, res, next) => {
|
|
const category = await categoryService.createCategory(req.body)
|
|
|
|
res.status(201).json({
|
|
status: 'success',
|
|
data: category,
|
|
})
|
|
})
|
|
|
|
exports.getCategory = catchAsync(async (req, res, next) => {
|
|
const category = await categoryService.getCategory(req.params.categoryId)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: category,
|
|
})
|
|
})
|
|
|
|
exports.updateCategory = catchAsync(async (req, res, next) => {
|
|
const category = await categoryService.updateCategory(req.params.categoryId, req.body)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: category,
|
|
})
|
|
})
|
|
|
|
exports.deleteCategory = catchAsync(async (req, res, next) => {
|
|
await categoryService.deleteCategory(req.params.categoryId)
|
|
|
|
res.status(204).json({
|
|
status: 'success',
|
|
data: null,
|
|
})
|
|
})
|