67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
// /components/classes/classController.js
|
|
'use strict';
|
|
|
|
const catchAsync = require('../../utils/catchAsync');
|
|
const classService = require('./classService');
|
|
const { successResponse, listResponse } = require('../../utils/apiResponse');
|
|
|
|
exports.getAll = catchAsync(async (req, res) => {
|
|
const { data, meta } = await classService.getAll(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.getOne = catchAsync(async (req, res) => {
|
|
const cls = await classService.getOne(req.params.id);
|
|
return successResponse(res, 200, 'Class retrieved successfully', cls);
|
|
});
|
|
|
|
exports.create = catchAsync(async (req, res) => {
|
|
const cls = await classService.create(req.body);
|
|
return successResponse(res, 201, 'Class created successfully', cls);
|
|
});
|
|
|
|
exports.update = catchAsync(async (req, res) => {
|
|
const cls = await classService.update(req.params.id, req.body);
|
|
return successResponse(res, 200, 'Class updated successfully', cls);
|
|
});
|
|
|
|
exports.delete = catchAsync(async (req, res) => {
|
|
await classService.remove(req.params.id);
|
|
return successResponse(res, 200, 'Class deleted successfully');
|
|
});
|
|
|
|
exports.restore = catchAsync(async (req, res) => {
|
|
const cls = await classService.restore(req.params.id);
|
|
return successResponse(res, 200, 'Class restored successfully', cls);
|
|
});
|
|
|
|
exports.registerUsers = catchAsync(async (req, res) => {
|
|
const cls = await classService.registerUsers(req.params.id, req.body.userIds || [], req.body);
|
|
return successResponse(res, 200, 'Users registered in class successfully', cls);
|
|
});
|
|
|
|
exports.removeUser = catchAsync(async (req, res) => {
|
|
const cls = await classService.removeUser(req.params.id, req.params.userId);
|
|
return successResponse(res, 200, 'User removed from class successfully', cls);
|
|
});
|
|
|
|
exports.getMyClasses = catchAsync(async (req, res) => {
|
|
const { data, meta } = await classService.getMyClasses(req.user._id, req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.getPublicClasses = catchAsync(async (req, res) => {
|
|
const { data, meta } = await classService.getPublicClasses(req.query);
|
|
return listResponse(res, 200, data, meta);
|
|
});
|
|
|
|
exports.getPublicOne = catchAsync(async (req, res) => {
|
|
const cls = await classService.getPublicOne(req.params.id);
|
|
return successResponse(res, 200, 'Class retrieved successfully', cls);
|
|
});
|
|
|
|
exports.sendClassPlanToProfessor = catchAsync(async (req, res) => {
|
|
const result = await classService.sendClassPlanToProfessor(req.params.id);
|
|
return successResponse(res, 200, 'برنامه کلاس با موفقیت برای استاد ارسال شد.', result);
|
|
});
|