Add finalize querystring for incrementing win streak and resetting vote counts
This commit is contained in:
parent
32a4062ea0
commit
08084b0ab9
1 changed files with 18 additions and 3 deletions
|
|
@ -1,11 +1,20 @@
|
|||
import { Request, ResponseToolkit } from "@hapi/hapi";
|
||||
import { Request, ResponseToolkit, ServerRoute } from "@hapi/hapi";
|
||||
import { config, db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
export default {
|
||||
const route: ServerRoute = {
|
||||
method: `GET`, path: `/{guild_id}/bracket/winners`,
|
||||
options: {
|
||||
validate: {
|
||||
query: Joi.object({
|
||||
finalize: Joi.boolean().optional().default(false),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request: Request, h: ResponseToolkit) {
|
||||
let gID = request.params.guild_id;
|
||||
let data = db[gID].bracket;
|
||||
let { finalize } = request.query;
|
||||
|
||||
let winners: quote[] = [];
|
||||
let highest = -1;
|
||||
|
|
@ -13,6 +22,11 @@ export default {
|
|||
// Run through all of the quotes to find the most voted for ones
|
||||
for (var quote of data.quotes) {
|
||||
|
||||
if (finalize) {
|
||||
quote.win_streak++;
|
||||
quote.votes = 0;
|
||||
};
|
||||
|
||||
// New maximum, remove all previous winners
|
||||
if (quote.votes > highest) {
|
||||
winners = [ quote ];
|
||||
|
|
@ -31,4 +45,5 @@ export default {
|
|||
eliminate_all: count > Math.floor(config.guilds[gID].quote_max / 2),
|
||||
}).code(200);
|
||||
},
|
||||
}
|
||||
};
|
||||
export default route;
|
||||
Loading…
Add table
Add a link
Reference in a new issue