mirror of
https://github.com/xfarrow/blink
synced 2025-04-24 18:18:40 +02:00
adding filter organization
This commit is contained in:
parent
6bd04adccb
commit
4f92f2dab5
@ -110,6 +110,17 @@ async function remove(organizationId, requester) {
|
|||||||
return numberOfDeletedRows == 1;
|
return numberOfDeletedRows == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of Organizations given their prefix.
|
||||||
|
* E.g. "Can" --> "Canonical"
|
||||||
|
* @param {*} name
|
||||||
|
*/
|
||||||
|
async function filterByPrefix(name) {
|
||||||
|
return await knex('Organization')
|
||||||
|
.where('name', 'ilike', `${name}%`)
|
||||||
|
.select('name', 'location');
|
||||||
|
}
|
||||||
|
|
||||||
// Exporting a function
|
// Exporting a function
|
||||||
// means making a JavaScript function defined in one
|
// means making a JavaScript function defined in one
|
||||||
// module available for use in another module.
|
// module available for use in another module.
|
||||||
@ -118,5 +129,6 @@ module.exports = {
|
|||||||
createOrganization,
|
createOrganization,
|
||||||
insert,
|
insert,
|
||||||
update,
|
update,
|
||||||
remove
|
remove,
|
||||||
|
filterByPrefix
|
||||||
};
|
};
|
@ -163,11 +163,24 @@ async function getOrganization(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function filterByPrefix(req, res) {
|
||||||
|
try {
|
||||||
|
const organizations = await Organization.filterByPrefix(req.body.name);
|
||||||
|
return res.status(200).json(organizations).send();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error in function ${getOrganization.name}: ${error}`);
|
||||||
|
return res.status(500).json({
|
||||||
|
error: 'Internal server error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Here we can not use the jwtUtils.verifyToken as the Router's middleware directly, as the latter
|
// Here we can not use the jwtUtils.verifyToken as the Router's middleware directly, as the latter
|
||||||
// will be mounted under /organizations, but there are other resources under /organizations
|
// will be mounted under /organizations, but there are other resources under /organizations
|
||||||
// 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('/', 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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user