50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const AppError = require('../../globalErrorHandler/AppError')
|
|
const Role = require('./roleModel')
|
|
const roleService = require('./roleService')
|
|
|
|
exports.getAllRoles = catchAsync(async (req, res, next) => {
|
|
const roles = await roleService.getAllRoles()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: roles.length,
|
|
data: roles,
|
|
})
|
|
})
|
|
|
|
exports.createRole = catchAsync(async (req, res, next) => {
|
|
const role = await roleService.createRole(req.body)
|
|
|
|
res.status(201).json({
|
|
status: 'success',
|
|
data: role,
|
|
})
|
|
})
|
|
|
|
exports.getRole = catchAsync(async (req, res, next) => {
|
|
const role = await roleService.getRole(req.params.roleId)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: role,
|
|
})
|
|
})
|
|
|
|
exports.updateRole = catchAsync(async (req, res, next) => {
|
|
const updateRole = await roleService.updateRole(req.params.roleId, req.body)
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: updateRole,
|
|
})
|
|
})
|
|
|
|
exports.deleteRole = catchAsync(async (req, res, next) => {
|
|
await roleService.deleteRole(req.params.roleId)
|
|
|
|
res.status(204).json({
|
|
status: 'success',
|
|
data: null,
|
|
})
|
|
})
|