Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// /components/sessions/sessionController.js
|
||||
|
||||
const catchAsync = require('../../utils/catchAsync');
|
||||
const sessionService = require('./sessionService');
|
||||
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
||||
|
||||
exports.create = catchAsync(async (req, res, next) => {
|
||||
const actorId = req.user?._id;
|
||||
const session = await sessionService.createSession(req.body, actorId);
|
||||
return successResponse(res, 201, 'Session created successfully', session);
|
||||
});
|
||||
|
||||
exports.getOne = catchAsync(async (req, res, next) => {
|
||||
const session = await sessionService.getSessionById(req.params.id);
|
||||
return successResponse(res, 200, 'Session retrieved successfully', session);
|
||||
});
|
||||
|
||||
exports.getAll = catchAsync(async (req, res, next) => {
|
||||
const { data, meta } = await sessionService.getAllSessions(req.query);
|
||||
return listResponse(res, 200, data, meta);
|
||||
});
|
||||
|
||||
exports.update = catchAsync(async (req, res, next) => {
|
||||
const actorId = req.user?._id;
|
||||
const session = await sessionService.updateSession(req.params.id, req.body, actorId);
|
||||
return successResponse(res, 200, 'Session updated successfully', session);
|
||||
});
|
||||
|
||||
exports.delete = catchAsync(async (req, res, next) => {
|
||||
await sessionService.deleteSession(req.params.id);
|
||||
return successResponse(res, 200, 'Session deleted successfully');
|
||||
});
|
||||
|
||||
exports.bulkDelete = catchAsync(async (req, res, next) => {
|
||||
const result = await sessionService.bulkDeleteSessions(req.body.ids || req.body.sessionIds);
|
||||
return successResponse(res, 200, 'Sessions deleted successfully', result);
|
||||
});
|
||||
|
||||
exports.bulkUpdateStatus = catchAsync(async (req, res, next) => {
|
||||
const actorId = req.user?._id;
|
||||
const result = await sessionService.bulkUpdateSessionStatus(
|
||||
req.body.ids || req.body.sessionIds,
|
||||
req.body.status,
|
||||
actorId
|
||||
);
|
||||
return successResponse(res, 200, 'Session statuses updated successfully', result);
|
||||
});
|
||||
|
||||
exports.search = catchAsync(async (req, res, next) => {
|
||||
const { data, meta } = await sessionService.searchSessions(req.query);
|
||||
return listResponse(res, 200, data, meta);
|
||||
});
|
||||
|
||||
exports.updateAttendance = catchAsync(async (req, res, next) => {
|
||||
const recordedBy = req.user?._id;
|
||||
const session = await sessionService.updateSessionAttendance(req.params.id, req.body.attendanceList, recordedBy);
|
||||
return successResponse(res, 200, 'Session attendance updated successfully', session);
|
||||
});
|
||||
|
||||
exports.getMySessions = catchAsync(async (req, res, next) => {
|
||||
const { data, meta } = await sessionService.getMySessions(req.user._id, req.query);
|
||||
return listResponse(res, 200, data, meta);
|
||||
});
|
||||
Reference in New Issue
Block a user