mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	adding filter organization
This commit is contained in:
		| @@ -110,6 +110,17 @@ async function remove(organizationId, requester) { | ||||
|   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 | ||||
| // means making a JavaScript function defined in one | ||||
| // module available for use in another module. | ||||
| @@ -118,5 +129,6 @@ module.exports = { | ||||
|   createOrganization, | ||||
|   insert, | ||||
|   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 | ||||
| // will be mounted under /organizations, but there are other resources under /organizations | ||||
| // that do not require the authorization, e.g. job offers | ||||
| const routes = express.Router(); | ||||
| routes.get('/:id', organizationValidator.deleteOrGetOrganizationValidator, getOrganization); | ||||
| routes.post('/filterByPrefix', filterByPrefix); | ||||
| routes.post('/', jwtUtils.verifyToken, organizationValidator.createOrganizationValidator, createOrganization); | ||||
| routes.patch('/:id', jwtUtils.verifyToken, organizationValidator.updateOrganizationValidator, updateOrganization); | ||||
| routes.delete('/:id', jwtUtils.verifyToken, organizationValidator.deleteOrGetOrganizationValidator, deleteOrganization); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user