diff --git a/app/middleware/acl.js b/app/middleware/acl.js index e0da9b607..c288ba4ec 100644 --- a/app/middleware/acl.js +++ b/app/middleware/acl.js @@ -94,6 +94,10 @@ const SPECIAL_CASES = [ PUT: [{name: 'admin'}, {name: 'manager'}, {name: 'appendix edit access'}], DELETE: [{name: 'admin'}, {name: 'manager'}, {name: 'appendix edit access'}], }, + { + path: pathToRegexp('/api/therapeutic-targets'), + GET: [{name: 'admin'}], + }, { path: pathToRegexp('/api/project'), POST: [{name: 'admin'}, {name: 'manager'}, {name: 'create project access'}], diff --git a/app/routes/index.js b/app/routes/index.js index c1176134f..2664c476c 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -20,6 +20,7 @@ const variantTextRoute = require('./variantText'); const templateRoute = require('./template'); const appendixRoute = require('./appendix'); const legendRoute = require('./legend'); +const therapeuticTargetsRoute = require('./therapeuticTargets'); // Get module route files const RouterInterface = require('./routingInterface'); @@ -105,6 +106,9 @@ class Routing extends RouterInterface { // Global legend routes this.router.use('/legend', legendRoute); + // Get therapeutic targets routes (all reports) + this.router.use('/therapeutic-targets', therapeuticTargetsRoute); + return true; } } diff --git a/app/routes/swagger/swagger.json b/app/routes/swagger/swagger.json index 5edea12f4..1480ae6d3 100644 --- a/app/routes/swagger/swagger.json +++ b/app/routes/swagger/swagger.json @@ -2187,6 +2187,41 @@ } } }, + "/therapeutic-targets": { + "get": { + "summary": "Get All Therapeutic Targets", + "description": "Returns all therapeutic targets across all reports. Admin only.", + "tags": [ + "Therapeutic Targets" + ], + "security": [ + { + "basicAuth": [] + } + ], + "responses": { + "200": { + "description": "Returns all therapeutic targets across all reports", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/therapeuticTargetAssociations" + } + } + } + } + }, + "401": { + "$ref": "#/components/responses/UnauthorizedError" + }, + "403": { + "description": "User does not have permission to access this endpoint (admin only)" + } + } + } + }, "/project/{project}/therapeutic-targets": { "get": { "summary": "Get All Therapeutic Targets For a Project", diff --git a/app/routes/therapeuticTargets.js b/app/routes/therapeuticTargets.js new file mode 100644 index 000000000..e77f0cd2a --- /dev/null +++ b/app/routes/therapeuticTargets.js @@ -0,0 +1,32 @@ +const HTTP_STATUS = require('http-status-codes'); +const express = require('express'); + +const db = require('../models'); +const logger = require('../log'); + +const router = express.Router({mergeParams: true}); + +// Get all therapeutic targets across all reports (admin only, enforced in ACL middleware) +router.route('/') + .get(async (req, res) => { + try { + const results = await db.models.therapeuticTarget.scope('public').findAll({ + order: [['reportId', 'ASC'], ['rank', 'ASC']], + include: [ + { + model: db.models.report, + as: 'report', + attributes: ['ident'], + }, + ], + }); + return res.json(results); + } catch (error) { + logger.error(`Unable to retrieve therapeutic targets ${error}`); + return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ + error: {message: 'Unable to retrieve therapeutic targets'}, + }); + } + }); + +module.exports = router;