summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-05-04 22:30:44 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-05-04 22:30:44 +0200
commit8fc264f11b60884da9288299b6950ece1cf749f1 (patch)
tree7185fc6efd89ed8a88ba8d4b0a17ee57e0389e4f
parentfc737edb1e62fb298a429b6c8a484a3829031866 (diff)
downloadbridge-8fc264f11b60884da9288299b6950ece1cf749f1.tar.gz
bridge-8fc264f11b60884da9288299b6950ece1cf749f1.zip
add endpoint for team crunching
-rw-r--r--index.html11
-rw-r--r--server.js21
2 files changed, 31 insertions, 1 deletions
diff --git a/index.html b/index.html
index 8a699cc..f8d1c56 100644
--- a/index.html
+++ b/index.html
@@ -33,6 +33,12 @@
</form>
</p>
<p>
+ <form id="crunch-team-form">
+ <input type="text" id="crunch-team">
+ <input type="submit" value="Crunch Team by ID">
+ </form>
+ </p>
+ <p>
<form id="crunchglobal-form">
<input type="checkbox" id="crunch-force">
<label for="crunch-force">Force recrunch</label>
@@ -146,6 +152,11 @@
const ign = $("#crunch-name").val();
$.post("/api/player/" + ign + "/crunch");
});
+ $("#crunch-team-form").submit((e) => {
+ e.preventDefault();
+ const id = $("#crunch-team").val();
+ $.post("/api/team/" + id + "/crunch");
+ });
$("#crunchglobal-form").submit((e) => {
const force = $("#crunch-force").is(":checked");
e.preventDefault();
diff --git a/server.js b/server.js
index 98923f3..3004d39 100644
--- a/server.js
+++ b/server.js
@@ -368,6 +368,13 @@ async function crunchPlayer(api_id) {
// global stats would increase on every player refresh otherwise
}
+// reset fame and crunch
+// TODO: incremental crunch possible?
+async function crunchTeam(team_id) {
+ await ch.sendToQueue(CRUNCH_QUEUE, new Buffer(team_id),
+ { persistent: true, type: "team" });
+}
+
// crunch (force = recrunch) global stats
async function crunchGlobal(force=false) {
// get lcpid from keys table
@@ -472,7 +479,7 @@ app.post("/api/player/:name/update/:category*?", async (req, res) => {
app.post("/api/player/:name/crunch", async (req, res) => {
const player = await model.Player.findOne({ where: { name: req.params.name } });
if (player == undefined) {
- logger.warn("player not found in db, won't recrunch",
+ logger.error("player not found in db, won't recrunch",
{ name: req.params.name });
res.sendStatus(404);
return;
@@ -481,6 +488,18 @@ app.post("/api/player/:name/crunch", async (req, res) => {
crunchPlayer(player.api_id); // fire away
res.sendStatus(204);
});
+// crunch a known team
+app.post("/api/team/:id/crunch", async (req, res) => {
+ if (await model.Team.findOne({ where: { id: req.params.id } }) == undefined) {
+ logger.error("team not found in db, won't recrunch",
+ { name: req.params.id });
+ res.sendStatus(404);
+ return;
+ }
+ logger.info("team in db, recrunching", { name: req.params.id });
+ crunchTeam(req.params.id); // fire away
+ res.sendStatus(204);
+});
// update a random user
app.post("/api/player", async (req, res) => {
let player = await model.Player.findOne({ order: [ Seq.fn("RAND") ] });