From 5aa481f947f6cdaca9182c2cc9e7781fe60a83ad Mon Sep 17 00:00:00 2001 From: AlejandroSuero Date: Wed, 8 May 2024 22:23:49 +0200 Subject: [PATCH 1/3] fix(#951): applying team match vote --- src/pages/api/votes/[combatId].ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/api/votes/[combatId].ts b/src/pages/api/votes/[combatId].ts index a22d275a9..88fd59c57 100644 --- a/src/pages/api/votes/[combatId].ts +++ b/src/pages/api/votes/[combatId].ts @@ -34,7 +34,12 @@ export const POST: APIRoute = async ({ params, request }) => { if (!success) return res("Bad request", { status: 400 }) const { voteId } = output - const boxerData = combatData.boxers.find((b) => b === voteId) + const boxerData = combatData.boxers.find((b) => { + if (combatData.teams !== undefined) { + return voteId.includes(b) + } + return b === voteId + }) if (!boxerData) return res("Boxer not found", { status: 404 }) const userId = session.user.id From 18b447f0671bcf01bcecce2c63d69d1c833c3fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AoMe=20=C2=B7=20=E9=9D=92=E7=9B=AE?= <71392160+AlejandroSuero@users.noreply.github.com> Date: Thu, 9 May 2024 12:00:14 +0200 Subject: [PATCH 2/3] Update src/pages/api/votes/[combatId].ts Co-authored-by: Pere Joan Martorell --- src/pages/api/votes/[combatId].ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pages/api/votes/[combatId].ts b/src/pages/api/votes/[combatId].ts index 88fd59c57..75e9998a8 100644 --- a/src/pages/api/votes/[combatId].ts +++ b/src/pages/api/votes/[combatId].ts @@ -34,12 +34,13 @@ export const POST: APIRoute = async ({ params, request }) => { if (!success) return res("Bad request", { status: 400 }) const { voteId } = output - const boxerData = combatData.boxers.find((b) => { - if (combatData.teams !== undefined) { - return voteId.includes(b) - } - return b === voteId - }) + let boxerData; + if (combatData.teams !== undefined) { + boxerData = combatData.teams.find((t) => t === voteId) + } + else { + boxerData = combatData.boxers.find((b) => b === voteId) + } if (!boxerData) return res("Boxer not found", { status: 404 }) const userId = session.user.id From 4579e2f59a8d704c33970a23c073a9747c2ad7af Mon Sep 17 00:00:00 2001 From: AlejandroSuero Date: Thu, 9 May 2024 12:01:21 +0200 Subject: [PATCH 3/3] fix: formatted and added type --- src/pages/api/votes/[combatId].ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/api/votes/[combatId].ts b/src/pages/api/votes/[combatId].ts index 75e9998a8..e0c3dad40 100644 --- a/src/pages/api/votes/[combatId].ts +++ b/src/pages/api/votes/[combatId].ts @@ -34,11 +34,10 @@ export const POST: APIRoute = async ({ params, request }) => { if (!success) return res("Bad request", { status: 400 }) const { voteId } = output - let boxerData; + let boxerData: string | undefined if (combatData.teams !== undefined) { boxerData = combatData.teams.find((t) => t === voteId) - } - else { + } else { boxerData = combatData.boxers.find((b) => b === voteId) } if (!boxerData) return res("Boxer not found", { status: 404 })