From 6c709db09268b3ad230b9e7afd8e051dcbc1b7c1 Mon Sep 17 00:00:00 2001 From: ff137 Date: Fri, 15 Sep 2023 22:33:05 +0300 Subject: [PATCH] :art: refactor: move scenario route handlers to database module --- routes/handlers/database.js | 31 +++++++++++++++++++++++++++++++ routes/spec.js | 27 +++------------------------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/routes/handlers/database.js b/routes/handlers/database.js index c43918a09..28c1260e1 100644 --- a/routes/handlers/database.js +++ b/routes/handlers/database.js @@ -1,3 +1,4 @@ +const constants = require("dotaconstants"); const { Client } = require("pg"); const buildStatus = require("../../store/buildStatus"); const config = require("../../config"); @@ -187,6 +188,33 @@ function getHealth(req, res, cb) { }); } +function getItemTimings(req, res, cb) { + queries.getItemTimings(req, (err, result) => { + if (err) { + return cb(err); + } + return res.json(result.rows); + }); +} + +function getLaneRoles(req, res, cb) { + queries.getLaneRoles(req, (err, result) => { + if (err) { + return cb(err); + } + return res.json(result.rows); + }); +} + +function getTeamScenarios(req, res, cb) { + queries.getTeamScenarios(req, (err, result) => { + if (err) { + return cb(err); + } + return res.json(result.rows); + }); +} + module.exports = { explorer, getConstants, @@ -199,5 +227,8 @@ module.exports = { getReplayData, getRecordsByField, getRequestState, + getItemTimings, + getLaneRoles, + getTeamScenarios, requestParse, }; diff --git a/routes/spec.js b/routes/spec.js index 8a3cf49f1..23675d558 100644 --- a/routes/spec.js +++ b/routes/spec.js @@ -1521,14 +1521,7 @@ The OpenDota API offers 50,000 free calls per month and a rate limit of 60 reque }, }, route: () => "/scenarios/itemTimings", - func: (req, res, cb) => { - queries.getItemTimings(req, (err, result) => { - if (err) { - return cb(err); - } - return res.json(result.rows); - }); - }, + func: databaseHandler.getItemTimings, }, }, "/scenarios/laneRoles": { @@ -1565,14 +1558,7 @@ The OpenDota API offers 50,000 free calls per month and a rate limit of 60 reque }, }, route: () => "/scenarios/laneRoles", - func: (req, res, cb) => { - queries.getLaneRoles(req, (err, result) => { - if (err) { - return cb(err); - } - return res.json(result.rows); - }); - }, + func: databaseHandler.getLaneRoles, }, }, "/scenarios/misc": { @@ -1598,14 +1584,7 @@ The OpenDota API offers 50,000 free calls per month and a rate limit of 60 reque }, }, route: () => "/scenarios/misc", - func: (req, res, cb) => { - queries.getTeamScenarios(req, (err, result) => { - if (err) { - return cb(err); - } - return res.json(result.rows); - }); - }, + func: databaseHandler.getTeamScenarios, }, }, "/schema": {