Files
kavehhn f04c797be6 Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
2026-08-09 04:18:08 +02:00

36 lines
1.3 KiB
JavaScript

// /components/roles/roleController.js
const catchAsync = require('../../utils/catchAsync');
const roleService = require('./roleService');
const { successResponse, listResponse } = require('../../utils/apiResponse');
exports.createRole = catchAsync(async (req, res, next) => {
const role = await roleService.createRole(req.body);
return successResponse(res, 201, 'Role created successfully', role);
});
exports.getRole = catchAsync(async (req, res, next) => {
const role = await roleService.getRole(req.params.id);
return successResponse(res, 200, 'Role retrieved successfully', role);
});
exports.getAllRoles = catchAsync(async (req, res, next) => {
const { data, meta } = await roleService.getAllRoles(req.query);
return listResponse(res, 200, data, meta);
});
exports.updateRole = catchAsync(async (req, res, next) => {
const role = await roleService.updateRole(req.params.id, req.body);
return successResponse(res, 200, 'Role updated successfully', role);
});
exports.deleteRole = catchAsync(async (req, res, next) => {
await roleService.deleteRole(req.params.id);
return successResponse(res, 200, 'Role deleted successfully');
});
exports.searchRoles = catchAsync(async (req, res, next) => {
const { data, meta } = await roleService.searchRoles(req.query);
return listResponse(res, 200, data, meta);
});