33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
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 = Number(req.params.groupId || req.body.groupId);
|
|
|
|
if (isNaN(groupId)) throw new customError(`groupId is not a number`, responseCodes.responses.groups.id_not_found)
|
|
|
|
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 } |