Let admins skip SMS on user, class, and invoice actions, and let users change their own password with the current one.
47 lines
1.7 KiB
JavaScript
47 lines
1.7 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.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);
|
|
});
|