Skip to content

Commit

Permalink
drug-disease route handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Nov 11, 2024
1 parent 595e288 commit 1c05676
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions api_routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const { handleAxiosError } = require('./utils');
const services = require('./services');
const external_apis = require('./external');

const { getDrugDiseasePairs } = require('../explore/query/drug-disease');

const samples = JSON.parse(fs.readFileSync(path.join(__dirname, './sample-query-cache.json')));

router.use('/', external_apis);
Expand Down Expand Up @@ -58,10 +60,24 @@ router.route('/quick_answer')
}
});

// router.route('/explore')
// .post(async (req, res) => {
// res.status(200).send(drugDiseasePairs);
// });
router.route('/explore/drug-disease')
.post(async (req, res) => {
const { sort, filters, pagination } = req.body;

if (!pagination || !Number.isInteger(pagination.offset) || !Number.isInteger(pagination.limit)) return res.status(400).json({ error: 'Missing pagination' });
if (pagination.limit < 1 || pagination.offset < 0) return res.status(400).json({ error: 'Invalid limit or offset value' });

const limit = Math.min(pagination.limit, 500);
const { offset } = pagination;

try {
const results = await getDrugDiseasePairs({ sort, filters, pagination: { limit, offset } });
return res.status(200).json(results);
} catch (error) {
console.error('Error in explore page query:', error, req.body);
return res.status(500).json({ error: 'Internal server error' });
}
});

router.route('/answer')
.post(async (req, res) => {
Expand Down

0 comments on commit 1c05676

Please sign in to comment.