bsfe_server/src/middlewares/existance.js

21 lines
735 B
JavaScript
Raw Normal View History

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) => {
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 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 }