Allowed Licenses:
{
- licenses
- .filter(
- (license: License) =>
- Math.ceil(license.min_license_level / license.license_group) ===
- license.min_license_level / license.license_group
- )
- .map((license: License, index: number) => (
+ allowedLicenses.map((license: License, index: number) => (
{license.group_name}{" "}
{!index
diff --git a/src/pages/user/[id]/scheduling/index.astro b/src/pages/user/[id]/scheduling/index.astro
index 86caae6..8dde6e1 100644
--- a/src/pages/user/[id]/scheduling/index.astro
+++ b/src/pages/user/[id]/scheduling/index.astro
@@ -1,6 +1,7 @@
---
import { connectToDatabase } from "$lib/mongodb";
import DefaultLayout from "$lib/layouts/default.astro";
+// @todo Properly assert types in this file
export async function getStaticPaths() {
const dbConnection = await connectToDatabase();
const db = dbConnection.db;
@@ -66,26 +67,54 @@ const trackPackages = await userCollection
const trackIds = trackPackages
.map((trackPackage) => trackPackage.content_ids)
.flat();
+const carsCollection = db.collection("cars");
+const cars = await carsCollection.find().toArray();
+const carsMap = new Map();
+cars.forEach((car) => {
+ const { car_id } = car;
+ carsMap.set(car_id, car);
+});
const carClassCollection = db.collection("carclasses");
const carClassIdsForCarIds = await carClassCollection.distinct("car_class_id", {
"cars_in_class.car_id": { $in: carIds },
});
+const carClasses = await carClassCollection.find().toArray();
+const carClassesMap = new Map();
+carClasses.forEach((carClass) => {
+ const { car_class_id, cars_in_class } = carClass;
+ const carsInClass = cars_in_class.map((carInClass) =>
+ carsMap.get(carInClass.car_id)
+ );
+ carClassesMap.set(car_class_id, { ...carClass, cars_in_class: carsInClass });
+});
const seasonsCollection = db.collection("seasons");
-const seasons = await seasonsCollection
- .find({}, { })
- .toArray();
+const seasons = await seasonsCollection.find({}, {}).toArray();
const carClassIdSet = new Set(carClassIdsForCarIds);
const trackIdSet = new Set(trackIds);
+const licenseGroupToNameMap: Record = {
+ "1": "Rookie",
+ "2": "Class D",
+ "3": "Class C",
+ "4": "Class B",
+ "5": "Class A",
+};
const results = seasons
.map((season) => {
- const { _id, schedules, season_name, car_class_ids } = season;
- const tracks: Array> = schedules.map((schedule: any, index: number) => ({
- week: index + 1,
- ...schedule.track,
- }));
+ const { schedules, season_name, car_class_ids } = season;
+ const carClassData = car_class_ids.map((car_class_id: number) =>
+ carClassesMap.get(car_class_id)
+ );
+ const tracks: Array> = schedules.map(
+ (schedule: any, index: number) => ({
+ week: index + 1,
+ ...schedule.track,
+ })
+ );
const ownedTrackWeeks: Array = tracks
- .filter((track: Record) => trackIdSet.has(track.track_id))
- .map((track: Record) => Number(track.week));
+ .filter((track: Record) =>
+ trackIdSet.has(track.track_id)
+ )
+ .map((track: Record) => Number(track.week));
const trackPercentageOwned = Math.round(
(ownedTrackWeeks.length / tracks.length) * 100
);
@@ -93,8 +122,9 @@ const results = seasons
carClassIdSet.has(carClassId)
);
return {
- "Season ID": _id,
"Season Name": String(season_name),
+ "License Level": licenseGroupToNameMap[String(season.license_group)],
+ carClassData,
tracks,
ownedTrackWeeks,
"Own Car": ownedCarClasses.length ? "Yes" : "No",
@@ -105,7 +135,11 @@ const results = seasons
(a, b) =>
b["Overall Track Percentage Owned"] - a["Overall Track Percentage Owned"]
);
-const keysToOmitInTable = new Set(["tracks", "ownedTrackWeeks"]);
+const keysToOmitInTable = new Set([
+ "carClassData",
+ "tracks",
+ "ownedTrackWeeks",
+]);
---
@@ -117,28 +151,54 @@ const keysToOmitInTable = new Set(["tracks", "ownedTrackWeeks"]);
}
{
results.map((result) => (
-
+
{Object.keys(result)
.filter((key) => !keysToOmitInTable.has(key))
.map((key: string) => (
{result[key]}
))}
-
- {result.tracks.map((track) =>
- result.ownedTrackWeeks.includes(Number(track.week)) ? (
-
-
- {track.week}. {track.track_name} {track.config_name}
+
+
+ {result.carClassData.map((carClass) => (
+
+ {carClass.cars_in_class.map((car) =>
+ carIds.includes(car.car_id) ? (
+
+
Car Class: {carClass.name}
+
{car.car_name}
+
+ ) : (
+
+
Car Class: {carClass.name}
+
{car.car_name}
+
+ )
+ )}
-
- ) : (
-
-
- {track.week}. {track.track_name} {track.config_name}
-
-
- )
- )}
+ ))}
+
+
+ {result.tracks.map((track) =>
+ result.ownedTrackWeeks.includes(Number(track.week)) ? (
+
+ {track.week}. {track.track_name} {track.config_name}
+
+ ) : (
+
+ {track.week}. {track.track_name} {track.config_name}
+
+ )
+ )}
+
))
@@ -151,8 +211,8 @@ const keysToOmitInTable = new Set(["tracks", "ownedTrackWeeks"]);
Alpine.data("dropdown", () => ({
opened: false,
toggle() {
- this.opened = !this.opened
- }
+ this.opened = !this.opened;
+ },
}));
Alpine.start();