From cdc5ed5cf6cad3afdf1be554336ea6b991e392f0 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Mon, 19 Jul 2021 01:07:52 -0600 Subject: [PATCH] Check the all-elimination clause in the create bracket --- src/endpoints/management/create_bracket.ts | 10 +++++++--- src/endpoints/management/get_winners.ts | 7 +------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/endpoints/management/create_bracket.ts b/src/endpoints/management/create_bracket.ts index a1d2d70..0c74f32 100644 --- a/src/endpoints/management/create_bracket.ts +++ b/src/endpoints/management/create_bracket.ts @@ -30,7 +30,11 @@ export default { // Calculate the winners from the previous bracket let r = await request.server.inject(`/bracket/winners`); var quotes: string[] = JSON.parse(r.payload).winners; - var winner_count = quotes.length; + + // Ensure that the all elimination limit didn't get hit + if (quotes.length > Math.floor(config.discord.quote_max / 2)) { + quotes = []; + }; // Get any new quotes for the bracket quotes.push(...(await getQuote(config.discord.quote_max - quotes.length))); @@ -49,7 +53,7 @@ export default { { description: `Note: If **more than ${Math.floor(config.discord.quote_max / 2)}** of the quotes tie, they will all be eliminated, otherwise, the ones that tie will move on to the next bracket.`, fields: quotes.map((quote, i) => { return { - name: `${i < winner_count ? '👑 ' : ''}Quote: ${i + 1}`, + name: `${i < quotes.length ? '👑 ' : ''}Quote: ${i + 1}`, value: quote, }}), } @@ -66,7 +70,7 @@ export default { return { label: `Quote ${i + 1}`, value: i, - emoji: i < winner_count ? { + emoji: i < quotes.length ? { name: `👑` } : null } diff --git a/src/endpoints/management/get_winners.ts b/src/endpoints/management/get_winners.ts index e176b0f..e94060e 100644 --- a/src/endpoints/management/get_winners.ts +++ b/src/endpoints/management/get_winners.ts @@ -1,4 +1,4 @@ -import { config, db } from "@/main" +import { db } from "@/main" export default { method: `GET`, path: `/bracket/winners`, @@ -16,11 +16,6 @@ export default { }; }; - // Ensure that the all elimination limit didn't get hit - if (winners.length > Math.floor(config.discord.quote_max / 2)) { - return { winners: [] }; - }; - return { winners }; }, } \ No newline at end of file