From 463a87a3980d5be056bc4a45dbe4220953e00bcb Mon Sep 17 00:00:00 2001 From: ff137 Date: Fri, 15 Sep 2023 22:32:11 +0300 Subject: [PATCH] :art: refactor: move getConstants and getConstantsByResource route handler to database module --- routes/handlers/database.js | 14 ++++++++++++++ routes/spec.js | 12 ++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/routes/handlers/database.js b/routes/handlers/database.js index 3a86aa219..c43918a09 100644 --- a/routes/handlers/database.js +++ b/routes/handlers/database.js @@ -71,6 +71,18 @@ function getReplayData(req, res, cb) { }); } +function getConstants(req, res) { + return res.json(Object.keys(constants)); +} + +function getConstantsByResource(req, res, cb) { + const { resource } = req.params; + if (resource in constants) { + return res.json(constants[resource]); + } + return cb(); +} + function getRecordsByField(req, res, cb) { redis.zrevrange(`records:${req.params.field}`, 0, 99, "WITHSCORES", (err, rows) => { if (err) { @@ -177,6 +189,8 @@ function getHealth(req, res, cb) { module.exports = { explorer, + getConstants, + getConstantsByResource, getSchema, getHealth, getMmrDistributions, diff --git a/routes/spec.js b/routes/spec.js index 7183ef044..8a3cf49f1 100644 --- a/routes/spec.js +++ b/routes/spec.js @@ -1690,13 +1690,7 @@ The OpenDota API offers 50,000 free calls per month and a rate limit of 60 reque }, }, route: () => "/constants/:resource?", - func: (req, res, cb) => { - const { resource } = req.params; - if (resource in constants) { - return res.json(constants[resource]); - } - return cb(); - }, + func: databaseHandler.getConstantsByResource, }, }, "/constants": { @@ -1723,9 +1717,7 @@ The OpenDota API offers 50,000 free calls per month and a rate limit of 60 reque }, }, route: () => "/constants", - func: (req, res) => { - return res.json(Object.keys(constants)); - }, + func: databaseHandler.getConstants, }, }, },