mirror of
https://github.com/xfarrow/blink
synced 2025-02-18 08:20:36 +01:00
adding filter validator
This commit is contained in:
parent
4f92f2dab5
commit
b7144f1adb
@ -111,7 +111,7 @@ async function remove(organizationId, requester) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of Organizations given their prefix.
|
* Gets a list of Organizations given the prefix of their name.
|
||||||
* E.g. "Can" --> "Canonical"
|
* E.g. "Can" --> "Canonical"
|
||||||
* @param {*} name
|
* @param {*} name
|
||||||
*/
|
*/
|
||||||
|
@ -163,8 +163,14 @@ async function getOrganization(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterByPrefix(req, res) {
|
async function filter(req, res) {
|
||||||
try {
|
try {
|
||||||
|
const errors = organizationValidator.validationResult(req);
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
return res.status(400).json({
|
||||||
|
errors: errors.array()
|
||||||
|
});
|
||||||
|
}
|
||||||
const organizations = await Organization.filterByPrefix(req.body.name);
|
const organizations = await Organization.filterByPrefix(req.body.name);
|
||||||
return res.status(200).json(organizations).send();
|
return res.status(200).json(organizations).send();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -180,7 +186,7 @@ async function filterByPrefix(req, res) {
|
|||||||
// that do not require the authorization, e.g. job offers
|
// that do not require the authorization, e.g. job offers
|
||||||
const routes = express.Router();
|
const routes = express.Router();
|
||||||
routes.get('/:id', organizationValidator.deleteOrGetOrganizationValidator, getOrganization);
|
routes.get('/:id', organizationValidator.deleteOrGetOrganizationValidator, getOrganization);
|
||||||
routes.post('/filterByPrefix', filterByPrefix);
|
routes.post('/filter', organizationValidator.filterValidator, filter);
|
||||||
routes.post('/', jwtUtils.verifyToken, organizationValidator.createOrganizationValidator, createOrganization);
|
routes.post('/', jwtUtils.verifyToken, organizationValidator.createOrganizationValidator, createOrganization);
|
||||||
routes.patch('/:id', jwtUtils.verifyToken, organizationValidator.updateOrganizationValidator, updateOrganization);
|
routes.patch('/:id', jwtUtils.verifyToken, organizationValidator.updateOrganizationValidator, updateOrganization);
|
||||||
routes.delete('/:id', jwtUtils.verifyToken, organizationValidator.deleteOrGetOrganizationValidator, deleteOrganization);
|
routes.delete('/:id', jwtUtils.verifyToken, organizationValidator.deleteOrGetOrganizationValidator, deleteOrganization);
|
||||||
|
@ -42,9 +42,17 @@ const deleteOrGetOrganizationValidator = [
|
|||||||
check('id').notEmpty().escape()
|
check('id').notEmpty().escape()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const filterValidator = [
|
||||||
|
check('name').trim().notEmpty().escape().isLength({
|
||||||
|
min: 3, // to avoid database overhead
|
||||||
|
max: 128
|
||||||
|
}).withMessage('The name must be at least 3 characters and cannot exceed 128')
|
||||||
|
]
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validationResult,
|
validationResult,
|
||||||
createOrganizationValidator,
|
createOrganizationValidator,
|
||||||
updateOrganizationValidator,
|
updateOrganizationValidator,
|
||||||
deleteOrGetOrganizationValidator
|
deleteOrGetOrganizationValidator,
|
||||||
|
filterValidator
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user