Files

49 lines
2.0 KiB
JavaScript

// /components/professors/professorController.js
'use strict';
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.createFromUser = catchAsync(async (req, res, next) => {
const userId = req.body.userId || req.params.userId || req.body.id;
const result = await professorService.createProfessorFromUser(userId, req.body);
return successResponse(res, 201, 'Professor created from user successfully', result);
});
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);
});
exports.getPortal = catchAsync(async (req, res, next) => {
const userId = req.user?._id;
const data = await professorService.getProfessorPortalData(userId);
return successResponse(res, 200, 'Professor teaching portal data retrieved successfully', data);
});