2024-10-31 07:47:27 +03:00
|
|
|
import customError from '../response/customError.js';
|
|
|
|
import responseCodes from '../response/responseCodes.js';
|
|
|
|
import GroupService from '../services/group.js';
|
|
|
|
|
|
|
|
const groupExists = async (req, res, next) => {
|
2024-11-04 04:30:29 +03:00
|
|
|
let groupId = Number(req.params.groupId || req.body.groupId);
|
|
|
|
|
|
|
|
if (isNaN(groupId)) throw new customError(`groupId is not a number`, responseCodes.responses.groups.id_not_found)
|
2024-10-31 07:47:27 +03:00
|
|
|
|
|
|
|
let group = await GroupService.getById(groupId);
|
|
|
|
|
|
|
|
if (!group) throw new customError(`group does not exists`, responseCodes.responses.groups.id_not_found);
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
2024-10-31 10:06:49 +03:00
|
|
|
const groupNameExists = async (req, res, next) => {
|
|
|
|
let groupName = req.params.groupName || req.body.groupName;
|
|
|
|
|
|
|
|
let group = await GroupService.getByName(groupName);
|
|
|
|
|
|
|
|
if (!group) throw new customError(`group does not exists`, responseCodes.responses.groups.name_not_found);
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
2024-10-31 07:47:27 +03:00
|
|
|
const localIdExists = async (req, res, next) => {
|
|
|
|
let localId = req.params.localId || req.body.localId;
|
|
|
|
|
|
|
|
if (!localId) throw new customError(`local id is not specified`, responseCodes.responses.general.invalid_syntax);
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2024-10-31 10:06:49 +03:00
|
|
|
|
|
|
|
export default { groupExists, localIdExists, groupNameExists }
|