42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const AppError = require('../../globalErrorHandler/AppError')
|
|
const Category = require('./categoryModel')
|
|
const categoryService = require('./categoryService')
|
|
|
|
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,
|
|
})
|
|
})
|