|
|
|
@ -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; |
|
|
|
|