Skip to content

Commit

Permalink
🎨 refactor: move scenario route handlers to database module
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Sep 15, 2023
1 parent 463a87a commit 6c709db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
31 changes: 31 additions & 0 deletions routes/handlers/database.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const constants = require("dotaconstants");
const { Client } = require("pg");
const buildStatus = require("../../store/buildStatus");
const config = require("../../config");
Expand Down Expand Up @@ -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,
Expand All @@ -199,5 +227,8 @@ module.exports = {
getReplayData,
getRecordsByField,
getRequestState,
getItemTimings,
getLaneRoles,
getTeamScenarios,
requestParse,
};
27 changes: 3 additions & 24 deletions routes/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down

0 comments on commit 6c709db

Please sign in to comment.