Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
36 lines
1.4 KiB
JavaScript
36 lines
1.4 KiB
JavaScript
// /components/professors/professorController.js
|
|
|
|
const catchAsync = require('../../utils/catchAsync');
|
|
const professorService = require('./professorService');
|
|
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
|
|
|
exports.create = catchAsync(async (req, res, next) => {
|
|
const professor = await professorService.createProfessor(req.body);
|
|
return successResponse(res, 201, 'Professor created successfully', professor);
|
|
});
|
|
|
|
exports.getOne = catchAsync(async (req, res, next) => {
|
|
const professor = await professorService.getProfessorById(req.params.id);
|
|
return successResponse(res, 200, 'Professor retrieved successfully', professor);
|
|
});
|
|
|
|
exports.getAll = catchAsync(async (req, res, next) => {
|
|
const { data, meta } = await professorService.getAllProfessors(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.update = catchAsync(async (req, res, next) => {
|
|
const professor = await professorService.updateProfessor(req.params.id, req.body);
|
|
return successResponse(res, 200, 'Professor updated successfully', professor);
|
|
});
|
|
|
|
exports.delete = catchAsync(async (req, res, next) => {
|
|
await professorService.deleteProfessor(req.params.id);
|
|
return successResponse(res, 200, 'Professor deleted successfully');
|
|
});
|
|
|
|
exports.search = catchAsync(async (req, res, next) => {
|
|
const { data, meta } = await professorService.searchProfessors(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|