import customError from '../response/customError.js'; import responseCodes from '../response/responseCodes.js'; import GroupService from '../services/group.js'; const groupExists = async (req, res, next) => { let groupId = req.params.groupId || req.body.groupId; let group = await GroupService.getById(groupId); if (!group) throw new customError(`group does not exists`, responseCodes.responses.groups.id_not_found); next(); }; 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(); }; 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(); } export default { groupExists, localIdExists, groupNameExists }