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,43 @@
|
||||
// /components/courses/courseController.js
|
||||
|
||||
const catchAsync = require('../../utils/catchAsync');
|
||||
const courseService = require('./courseService');
|
||||
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
||||
|
||||
const isPublicRequest = (req) => String(req.originalUrl || req.path || '').includes('/user/');
|
||||
|
||||
exports.create = catchAsync(async (req, res) => {
|
||||
const actorId = req.user?._id;
|
||||
const course = await courseService.createCourse(req.body, actorId);
|
||||
return successResponse(res, 201, 'Course created successfully', course);
|
||||
});
|
||||
|
||||
exports.getOne = catchAsync(async (req, res) => {
|
||||
const course = await courseService.getCourseById(req.params.id, {
|
||||
publicOnly: isPublicRequest(req)
|
||||
});
|
||||
return successResponse(res, 200, 'Course retrieved successfully', course);
|
||||
});
|
||||
|
||||
exports.getAll = catchAsync(async (req, res) => {
|
||||
const { data, meta } = await courseService.getAllCourses(req.query, {
|
||||
publicOnly: isPublicRequest(req)
|
||||
});
|
||||
return listResponse(res, 200, data, meta);
|
||||
});
|
||||
|
||||
exports.update = catchAsync(async (req, res) => {
|
||||
const actorId = req.user?._id;
|
||||
const course = await courseService.updateCourse(req.params.id, req.body, actorId);
|
||||
return successResponse(res, 200, 'Course updated successfully', course);
|
||||
});
|
||||
|
||||
exports.delete = catchAsync(async (req, res) => {
|
||||
await courseService.deleteCourse(req.params.id);
|
||||
return successResponse(res, 200, 'Course deleted successfully');
|
||||
});
|
||||
|
||||
exports.search = catchAsync(async (req, res) => {
|
||||
const { data, meta } = await courseService.searchCourses(req.query);
|
||||
return listResponse(res, 200, data, meta);
|
||||
});
|
||||
Reference in New Issue
Block a user