Skip to content

Commit

Permalink
🎨 refactor: move getConstants and getConstantsByResource route handle…
Browse files Browse the repository at this point in the history
…r to database module
  • Loading branch information
ff137 committed Sep 15, 2023
1 parent 9db9772 commit 463a87a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 14 additions & 0 deletions routes/handlers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -177,6 +189,8 @@ function getHealth(req, res, cb) {

module.exports = {
explorer,
getConstants,
getConstantsByResource,
getSchema,
getHealth,
getMmrDistributions,
Expand Down
12 changes: 2 additions & 10 deletions routes/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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,
},
},
},
Expand Down

0 comments on commit 463a87a

Please sign in to comment.