From b510b24eb1ccf3cd290ccef62db8f7640d83ead3 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 16 Nov 2023 08:41:54 +0000 Subject: [PATCH] fix up data type mapping for the weekly standings --- server.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 283621a..0ba4bcf 100644 --- a/server.js +++ b/server.js @@ -27,6 +27,15 @@ class Season extends Document { } } +class SeasonRacer extends Document{ + constructor() { + super(); + + this.racer = Racer; + this.seasion = Season; + } +} + // Define the Races schema class Race extends Document { constructor() { @@ -125,7 +134,7 @@ function remapRaceInfo(raceRecord) { mapName: raceRecord.mapName, mapLink: raceRecord.mapLink, season: raceRecord.season, - results: [] + entries: [] } return modableRaceObject; @@ -150,18 +159,18 @@ app.get('/api/seasons/:id', async (req, res) => { const timeInMilliseconds = result.timeInMilliseconds; if (!fastestTimesMap.has(racerId) || timeInMilliseconds < fastestTimesMap.get(racerId)) { - fastestTimesMap.set(racerId, {"racer":racer, "timeInMilliseconds":timeInMilliseconds}); + fastestTimesMap.set(racerId, {"racer":result.racer, "timeInMilliseconds":timeInMilliseconds}); } }); fastestTimesMap.forEach((values, key) =>{ - modableRace.results.push({"racer":values.racer, "timeInMilliseconds":values.timeInMilliseconds, "position":0}) + modableRace.entries.push({"racer":values.racer, "timeInMilliseconds":values.timeInMilliseconds, "position":0}) }) - modableRace.results = Array.from(fastestTimesMap.entries()).map(([racerId, timeInMilliseconds]) => ({ - racerId, - timeInMilliseconds - })); + //modableRace.entries = Array.from(fastestTimesMap.entries()).map(([racerId, timeInMilliseconds]) => ({ + // racerId, + // timeInMilliseconds + //})); // This is wrong it will get only the racers the in last race it processes. racersInSeason = Array.from(new Set(raceResults.map(result => result.racer))); @@ -204,6 +213,16 @@ app.post('/api/race/add', verifyToken, async (req, res) => { res.json(race); }); +app.post('/api/racer/add', verifyToken, async (req, res) => { + const { name, gamerHandle, seasonId } = req.body; + const season = await Season.findOne({_id: seasonId}); + let existingRacer = await Racer.findOne({ gameHandle: gamerHandle }); + if (existingRacer == undefined) { + existingRacer = await Racer.create({ name, gamerHandle }); + existingRacer.save(); + } +}); + // route for handling requests from the Angular client app.post('/api/upload-replay', upload.single('file'), async (req, res) => { let file = req.file;