From 0e342396629e939e1b02661e15ab1c8a69f67951 Mon Sep 17 00:00:00 2001 From: Soren Zaiser Date: Sun, 29 Sep 2024 01:21:05 -0400 Subject: [PATCH] add alliance sync and fix AD spelling --- back-end/api/src/controllers/Results.ts | 39 +++++++++++++++++++ front-end/src/api/use-results-sync.ts | 15 +++++++ front-end/src/apps/admin/admin-app.tsx | 9 +++++ .../displays/seasons/fgc_2024/index.tsx | 2 +- .../scorekeeper/hooks/use-post-results.ts | 22 +++++++++-- 5 files changed, 83 insertions(+), 4 deletions(-) diff --git a/back-end/api/src/controllers/Results.ts b/back-end/api/src/controllers/Results.ts index 326e1ba0..33dcd41b 100644 --- a/back-end/api/src/controllers/Results.ts +++ b/back-end/api/src/controllers/Results.ts @@ -1,4 +1,5 @@ import { + AllianceMember, MatchKey, reconcileMatchDetails, reconcileMatchParticipants, @@ -140,6 +141,22 @@ export const postMatchResults = async ( ); }; +export const postAlliances = async ( + alliances: AllianceMember[], + platform: SyncPlatform, + apiKey: string +) => { + return await request( + '/upload/alliances', + { + method: 'POST', + body: JSON.stringify(alliances) + }, + platform, + apiKey + ); +}; + router.post( '/sync/rankings/:eventKey/:tournamentKey', async (req: Request, res: Response, next: NextFunction) => { @@ -250,4 +267,26 @@ router.post( } ); +router.post( + '/sync/aliances/:eventKey/:tournamentKey', + async (req: Request, res: Response, next: NextFunction) => { + logger.info( + environment.isProd() + ? 'attempting to sync results' + : 'not syncing results' + ); + if (!environment.isProd()) return res.send({ succuess: false }); + const { eventKey, tournamentKey } = req.params; + const { platform, apiKey } = req.body; + const db = await getDB(eventKey); + const alliances = await db.selectAllWhere('alliance', `eventKey = "${eventKey}" AND tournamentKey = "${tournamentKey}"`); + const allianceReq = await postAlliances( + alliances, + platform, + apiKey + ); + res.send({ succuess: allianceReq?.ok }); + } +); + export default router; diff --git a/front-end/src/api/use-results-sync.ts b/front-end/src/api/use-results-sync.ts index 247e45e7..776dbd69 100644 --- a/front-end/src/api/use-results-sync.ts +++ b/front-end/src/api/use-results-sync.ts @@ -51,6 +51,21 @@ export const resultsSyncRankings = ( } ); +export const resultsSyncAlliances = ( + eventKey: string, + tournamentKey: string, + platform: SyncPlatform, + apiKey: string +): Promise => + clientFetcher( + `results/sync/alliances/${eventKey}/${tournamentKey}`, + 'POST', + { + platform, + apiKey + } + ); + export const resultsSyncTeams = ( eventKey: string, platform: SyncPlatform, diff --git a/front-end/src/apps/admin/admin-app.tsx b/front-end/src/apps/admin/admin-app.tsx index 071e5f54..1908e81e 100644 --- a/front-end/src/apps/admin/admin-app.tsx +++ b/front-end/src/apps/admin/admin-app.tsx @@ -7,6 +7,7 @@ import { recalculatePlayoffsRankings } from 'src/api/use-ranking-data'; import { + resultsSyncAlliances, resultsSyncMatches, resultsSyncRankings } from 'src/api/use-results-sync'; @@ -50,6 +51,11 @@ export const AdminApp: FC = () => { await resultsSyncRankings(eventKey, tournamentKey, platform, apiKey); }; + const syncAlliances = async (): Promise => { + if (!tournamentKey) return; + await resultsSyncAlliances(eventKey, tournamentKey, platform, apiKey); + }; + const handlePurge = async (): Promise => { try { await purgeAll(); @@ -110,6 +116,9 @@ export const AdminApp: FC = () => { +