53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const AppError = require('../../globalErrorHandler/AppError')
|
|
const Permission = require('./permissionModel')
|
|
const permissionService = require('./permissionService')
|
|
|
|
exports.getAllPermissions = catchAsync(async (req, res, next) => {
|
|
const permissions = await permissionService.getAllPermissions()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: permissions.length,
|
|
data: permissions,
|
|
})
|
|
})
|
|
|
|
exports.createPermission = catchAsync(async (req, res, next) => {
|
|
const permission = await permissionService.createPermission(
|
|
req.body.englishName,
|
|
req.body.persianName
|
|
)
|
|
|
|
res.status(201).json({
|
|
status: 'success',
|
|
data: permission,
|
|
})
|
|
})
|
|
|
|
exports.getPermission = catchAsync(async (req, res, next) => {
|
|
const permission = await permissionService.getPermission(req.params.id)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: permission,
|
|
})
|
|
})
|
|
|
|
exports.updatePermission = catchAsync(async (req, res, next) => {
|
|
const updatePermission = await permissionService.updatePermission(data)
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: permission,
|
|
})
|
|
})
|
|
|
|
exports.deletePermission = catchAsync(async (req, res, next) => {
|
|
await permissionService.deletePermission(req.params.id)
|
|
|
|
res.status(204).json({
|
|
status: 'success',
|
|
data: null,
|
|
})
|
|
})
|