Я занят этим:
router.get('/get-by/',
passport.authenticate('jwt',{ session: false}),
[
query('field').not().isEmpty().withMessage('territory field is empty'),
query('value').not().isEmpty().withMessage('territory value is empty'),
],
function(req, res) {
var token = getToken(req.headers);
if (token) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.array() });
}
let filters = {}
filters[req.query.field] = req.query.value;
Territory.
findAll({
where: filters
})
.then((territory) => {
if (!territory) {
return res.status(401).send({
message: 'Territory not found.',
});
}
res.json({ success: true, territory: territory });
})
.catch((error) => res.status(400).send(error));
} else {
return res.status(403).send({success: false, msg: 'Unauthorized.'});
}
});