Init commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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.englishName,
|
||||
req.body.persianName
|
||||
)
|
||||
|
||||
res.status(201).json({
|
||||
status: 'success',
|
||||
data: role,
|
||||
})
|
||||
})
|
||||
|
||||
exports.getRole = catchAsync(async (req, res, next) => {
|
||||
const role = await roleService.getRole(req.body.id)
|
||||
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: role,
|
||||
})
|
||||
})
|
||||
|
||||
exports.updateRole = catchAsync(async (req, res, next) => {
|
||||
const updateRole = await roleService.updateRole(data)
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: role,
|
||||
})
|
||||
})
|
||||
|
||||
exports.deleteRole = catchAsync(async (req, res, next) => {
|
||||
await roleService.deleteRole(req.body.id)
|
||||
|
||||
res.status(204).json({
|
||||
status: 'success',
|
||||
data: null,
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user