diff --git a/lib/CompetitionHandling.ts b/lib/CompetitionHandling.ts index 5009c3f1..5573fa6e 100644 --- a/lib/CompetitionHandling.ts +++ b/lib/CompetitionHandling.ts @@ -54,12 +54,12 @@ export async function AssignScoutersToCompetitionMatches( teamId: string, competitionId: string, ) { - const comp = await db.findObjectById( + const comp = await db.findObjectById( CollectionId.Competitions, new ObjectId(competitionId), ); - const team = await db.findObject( + const team = await db.findObject( CollectionId.Teams, new ObjectId(teamId), ); @@ -99,7 +99,7 @@ export async function generateReportsForMatch( schedule?: ScheduleMatch, ) { if (typeof match === "string") { - const foundMatch = await db.findObjectById( + const foundMatch = await db.findObjectById( CollectionId.Matches, new ObjectId(match), ); @@ -114,7 +114,7 @@ export async function generateReportsForMatch( match.subjectiveScouter = schedule?.subjectiveScouter; const existingReportPromises = match.reports.map((r) => - db.findObjectById(CollectionId.Reports, new ObjectId(r)), + db.findObjectById(CollectionId.Reports, new ObjectId(r)), ); const existingReports = await Promise.all(existingReportPromises); diff --git a/lib/MongoDB.ts b/lib/MongoDB.ts index 054b1021..b3abced2 100644 --- a/lib/MongoDB.ts +++ b/lib/MongoDB.ts @@ -101,30 +101,30 @@ export class MongoDBInterface implements DbInterface { return Promise.resolve(); } - async findObjectById( - collection: CollectionId, - id: ObjectId, - ): Promise { + async findObjectById< + TId extends CollectionId, + TObj extends CollectionIdToType, + >(collection: TId, id: ObjectId): Promise { return (await this?.db ?.collection(collection) - .findOne({ _id: id })) as Type; + .findOne({ _id: id })) as TObj; } - async findObject( - collection: CollectionId, - query: object, - ): Promise { - return (await this?.db?.collection(collection).findOne(query)) as Type; + async findObject< + TId extends CollectionId, + TObj extends CollectionIdToType, + >(collection: TId, query: object): Promise { + return (await this?.db?.collection(collection).findOne(query)) as TObj; } - async findObjects( - collection: CollectionId, - query: object, - ): Promise { + async findObjects< + TId extends CollectionId, + TObj extends CollectionIdToType, + >(collection: TId, query: object): Promise { return (await this?.db ?.collection(collection) .find(query) - .toArray()) as Type[]; + .toArray()) as TObj[]; } async countObjects( diff --git a/lib/UrlResolver.ts b/lib/UrlResolver.ts index ab254422..6670398b 100644 --- a/lib/UrlResolver.ts +++ b/lib/UrlResolver.ts @@ -81,17 +81,17 @@ export default async function UrlResolver( try { const promises = [ - db.findObject(CollectionId.Teams, { slug: teamSlug }), + db.findObject(CollectionId.Teams, { slug: teamSlug }), seasonSlug - ? db.findObject(CollectionId.Seasons, { slug: seasonSlug }) + ? db.findObject(CollectionId.Seasons, { slug: seasonSlug }) : null, competitionSlug - ? db.findObject(CollectionId.Competitions, { + ? db.findObject(CollectionId.Competitions, { slug: competitionSlug, }) : null, reportId - ? db.findObject(CollectionId.Reports, { + ? db.findObject(CollectionId.Reports, { _id: new ObjectId(reportId), }) : null, diff --git a/lib/api/AccessLevels.ts b/lib/api/AccessLevels.ts index 9f95c0e3..d4e3c023 100644 --- a/lib/api/AccessLevels.ts +++ b/lib/api/AccessLevels.ts @@ -68,7 +68,7 @@ namespace AccessLevels { const team = await ( await db - ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); + ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); if (!team) { return { authorized: false, authData: undefined }; } @@ -92,7 +92,7 @@ namespace AccessLevels { const team = await ( await db - ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); + ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); if (!team) { return { authorized: false, authData: undefined }; } @@ -116,7 +116,7 @@ namespace AccessLevels { const comp = await ( await db - ).findObjectById( + ).findObjectById( CollectionId.Competitions, new ObjectId(compId), ); @@ -148,7 +148,7 @@ namespace AccessLevels { const season = await ( await db - ).findObjectById(CollectionId.Seasons, new ObjectId(seasonId)); + ).findObjectById(CollectionId.Seasons, new ObjectId(seasonId)); if (!season) { return { authorized: false, authData: undefined }; } @@ -177,7 +177,7 @@ namespace AccessLevels { const match = await ( await db - ).findObjectById(CollectionId.Matches, new ObjectId(matchId)); + ).findObjectById(CollectionId.Matches, new ObjectId(matchId)); if (!match) { return { authorized: false, authData: undefined }; } @@ -211,7 +211,7 @@ namespace AccessLevels { const report = await ( await db - ).findObjectById(CollectionId.Reports, new ObjectId(reportId)); + ).findObjectById(CollectionId.Reports, new ObjectId(reportId)); if (!report) { return { authorized: false, authData: undefined }; } @@ -240,7 +240,7 @@ namespace AccessLevels { const comp = await ( await db - ).findObjectById( + ).findObjectById( CollectionId.Competitions, new ObjectId(compId), ); @@ -272,7 +272,7 @@ namespace AccessLevels { const match = await ( await db - ).findObjectById(CollectionId.Matches, new ObjectId(matchId)); + ).findObjectById(CollectionId.Matches, new ObjectId(matchId)); if (!match) { return { authorized: false, authData: undefined }; } @@ -306,7 +306,7 @@ namespace AccessLevels { const pitReport = await ( await db - ).findObjectById( + ).findObjectById( CollectionId.PitReports, new ObjectId(pitReportId), ); @@ -343,7 +343,7 @@ namespace AccessLevels { const report = await ( await db - ).findObjectById(CollectionId.Reports, new ObjectId(reportId)); + ).findObjectById(CollectionId.Reports, new ObjectId(reportId)); if (!report) { return { authorized: false, authData: undefined }; } @@ -372,7 +372,7 @@ namespace AccessLevels { const report = await ( await db - ).findObjectById( + ).findObjectById( CollectionId.SubjectiveReports, new ObjectId(reportId), ); @@ -404,7 +404,7 @@ namespace AccessLevels { const picklist = await ( await db - ).findObjectById( + ).findObjectById( CollectionId.Picklists, new ObjectId(picklistId), ); diff --git a/lib/api/ApiUtils.ts b/lib/api/ApiUtils.ts index c2b49a26..4f47703d 100644 --- a/lib/api/ApiUtils.ts +++ b/lib/api/ApiUtils.ts @@ -35,19 +35,19 @@ export function ownsTeam(team?: Team | null, user?: User) { } export function getCompFromReport(db: DbInterface, report: Report) { - return db.findObject(CollectionId.Competitions, { + return db.findObject(CollectionId.Competitions, { matches: report.match?.toString(), }); } export function getCompFromMatch(db: DbInterface, match: Match) { - return db.findObject(CollectionId.Competitions, { + return db.findObject(CollectionId.Competitions, { matches: match._id?.toString(), }); } export function getCompFromPitReport(db: DbInterface, report: Pitreport) { - return db.findObject(CollectionId.Competitions, { + return db.findObject(CollectionId.Competitions, { pitReports: report._id?.toString(), }); } @@ -57,7 +57,7 @@ export function getCompFromSubjectiveReport( report: SubjectiveReport, ) { return db - .findObject(CollectionId.Matches, { + .findObject(CollectionId.Matches, { subjectiveReports: report._id?.toString(), }) .then((match) => { @@ -71,19 +71,19 @@ export function getCompFromPicklist( db: DbInterface, picklist: CompPicklistGroup, ) { - return db.findObject(CollectionId.Competitions, { + return db.findObject(CollectionId.Competitions, { picklist: picklist._id?.toString(), }); } export function getSeasonFromComp(db: DbInterface, comp: Competition) { - return db.findObject(CollectionId.Seasons, { + return db.findObject(CollectionId.Seasons, { competitions: comp?._id?.toString(), // Specifying one value is effectively includes for arrays }); } export function getTeamFromSeason(db: DbInterface, season: Season) { - return db.findObject(CollectionId.Teams, { + return db.findObject(CollectionId.Teams, { seasons: season._id?.toString(), }); } diff --git a/lib/api/ClientApi.ts b/lib/api/ClientApi.ts index 50e6b158..edd1d360 100644 --- a/lib/api/ClientApi.ts +++ b/lib/api/ClientApi.ts @@ -91,7 +91,7 @@ export default class ClientApi extends NextApiTemplate { handler: async (req, res, { db, userPromise }, authData, [teamId]) => { let team = await ( await db - ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); + ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); if (!team) { return res.error(404, "Team not found"); @@ -130,12 +130,12 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const teamPromise = db.findObjectById( + const teamPromise = db.findObjectById( CollectionId.Teams, new ObjectId(teamId.toString()), ); - const joineePromise = db.findObjectById( + const joineePromise = db.findObjectById( CollectionId.Users, new ObjectId(userId.toString()), ); @@ -239,7 +239,7 @@ export default class ClientApi extends NextApiTemplate { const db = await dbPromise; // Find if team already exists - const existingTeam = await db.findObject(CollectionId.Teams, { + const existingTeam = await db.findObject(CollectionId.Teams, { number, ...(league === League.FRC ? { $or: [{ league: League.FRC }, { league: undefined }] } @@ -593,7 +593,7 @@ export default class ClientApi extends NextApiTemplate { const usedComps = usePublicData && comp.tbaId !== NotLinkedToTba - ? await db.findObjects(CollectionId.Competitions, { + ? await db.findObjects(CollectionId.Competitions, { publicData: true, tbaId: comp.tbaId, gameId: comp.gameId, @@ -603,7 +603,7 @@ export default class ClientApi extends NextApiTemplate { if (usePublicData && !comp.publicData) usedComps.push(comp); const reports = ( - await db.findObjects(CollectionId.Reports, { + await db.findObjects(CollectionId.Reports, { match: { $in: usedComps.flatMap((m) => m.matches) }, submitted: submitted ? true : { $exists: true }, }) @@ -635,7 +635,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const matches = await db.findObjects(CollectionId.Matches, { + const matches = await db.findObjects(CollectionId.Matches, { _id: { $in: comp.matches.map((matchId) => new ObjectId(matchId)) }, }); return res.status(200).send(matches); @@ -659,7 +659,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const reports = await db.findObjects(CollectionId.Reports, { + const reports = await db.findObjects(CollectionId.Reports, { _id: { $in: match.reports.map((reportId) => new ObjectId(reportId)) }, }); return res.status(200).send(reports); @@ -766,14 +766,14 @@ export default class ClientApi extends NextApiTemplate { [teamId, targetUserId], ) => { const db = await dbPromise; - const targetUserPromise = db.findObjectById( + const targetUserPromise = db.findObjectById( CollectionId.Users, new ObjectId(targetUserId), ); if (!team.slackWebhook) throw new SlackNotLinkedError(res); - const webhookHolder = await db.findObjectById( + const webhookHolder = await db.findObjectById( CollectionId.Webhooks, new ObjectId(team.slackWebhook), ); @@ -996,10 +996,10 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const matches = await db.findObjects(CollectionId.Matches, { + const matches = await db.findObjects(CollectionId.Matches, { _id: { $in: comp.matches.map((matchId) => new ObjectId(matchId)) }, }); - const allReports = await db.findObjects(CollectionId.Reports, { + const allReports = await db.findObjects(CollectionId.Reports, { match: { $in: matches.map((match) => match?._id?.toString()) }, }); const reports = allReports.filter((report) => report.submitted); @@ -1091,7 +1091,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const pitReports = await db.findObjects( + const pitReports = await db.findObjects( CollectionId.PitReports, { _id: { $in: comp.pitReports.map((id) => new ObjectId(id)) }, @@ -1144,7 +1144,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const reports = await db.findObjects(CollectionId.Reports, { + const reports = await db.findObjects(CollectionId.Reports, { match: { $in: comp.matches }, }); @@ -1186,7 +1186,7 @@ export default class ClientApi extends NextApiTemplate { for (const scouterId of team?.scouters) { promises.push( db - .findObjectById(CollectionId.Users, new ObjectId(scouterId)) + .findObjectById(CollectionId.Users, new ObjectId(scouterId)) .then((scouter) => scouter && scouters.push(scouter)), ); } @@ -1194,14 +1194,14 @@ export default class ClientApi extends NextApiTemplate { for (const matchId of comp.matches) { promises.push( db - .findObjectById(CollectionId.Matches, new ObjectId(matchId)) + .findObjectById(CollectionId.Matches, new ObjectId(matchId)) .then((match) => match && matches.push(match)), ); } promises.push( db - .findObjects(CollectionId.Reports, { + .findObjects(CollectionId.Reports, { match: { $in: comp.matches }, }) .then((r) => quantitativeReports.push(...r)), @@ -1209,7 +1209,7 @@ export default class ClientApi extends NextApiTemplate { promises.push( db - .findObjects(CollectionId.PitReports, { + .findObjects(CollectionId.PitReports, { _id: { $in: comp.pitReports.map((id) => new ObjectId(id)) }, submitted: true, }) @@ -1218,7 +1218,7 @@ export default class ClientApi extends NextApiTemplate { promises.push( db - .findObjects(CollectionId.SubjectiveReports, { + .findObjects(CollectionId.SubjectiveReports, { match: { $in: comp.matches }, }) .then((r) => subjectiveReports.push(...r)), @@ -1247,7 +1247,7 @@ export default class ClientApi extends NextApiTemplate { handler: async (req, res, { db: dbPromise }, { comp }, [compId]) => { const db = await dbPromise; - const picklist = await db.findObjectById( + const picklist = await db.findObjectById( CollectionId.Picklists, new ObjectId(comp.picklist), ); @@ -1434,7 +1434,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const reports = await db.findObjects( + const reports = await db.findObjects( CollectionId.SubjectiveReports, { match: { $in: comp.matches }, @@ -1657,7 +1657,7 @@ export default class ClientApi extends NextApiTemplate { } const matchIds = matches.map((match) => match._id?.toString()); - const reports = await db.findObjects( + const reports = await db.findObjects( CollectionId.SubjectiveReports, { match: { $in: matchIds }, @@ -1685,7 +1685,7 @@ export default class ClientApi extends NextApiTemplate { ) => { const db = await dbPromise; - const removedUserPromise = db.findObjectById( + const removedUserPromise = db.findObjectById( CollectionId.Users, new ObjectId(userId), ); @@ -1736,7 +1736,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const user = await db.findObjectById( + const user = await db.findObjectById( CollectionId.Users, new ObjectId(id), ); @@ -1753,7 +1753,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [ids]) => { const db = await dbPromise; - const users = await db.findObjects(CollectionId.Users, { + const users = await db.findObjects(CollectionId.Users, { _id: { $in: ids.map((id) => new ObjectId(id)) }, }); return res.status(200).send(users); @@ -1769,7 +1769,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const team = await db.findObjectById( + const team = await db.findObjectById( CollectionId.Teams, new ObjectId(id), ); @@ -1801,7 +1801,7 @@ export default class ClientApi extends NextApiTemplate { } : { number: number, league: league }; - const team = await db.findObject(CollectionId.Teams, query); + const team = await db.findObject(CollectionId.Teams, query); return res.status(200).send(team); }, @@ -1816,7 +1816,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const season = await db.findObjectById( + const season = await db.findObjectById( CollectionId.Seasons, new ObjectId(id), ); @@ -1833,7 +1833,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const competition = await db.findObjectById( + const competition = await db.findObjectById( CollectionId.Competitions, new ObjectId(id), ); @@ -1850,7 +1850,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const match = await db.findObjectById( + const match = await db.findObjectById( CollectionId.Matches, new ObjectId(id), ); @@ -1867,7 +1867,7 @@ export default class ClientApi extends NextApiTemplate { isAuthorized: AccessLevels.AlwaysAuthorized, handler: async (req, res, { db: dbPromise }, authData, [id]) => { const db = await dbPromise; - const report = await db.findObjectById( + const report = await db.findObjectById( CollectionId.Reports, new ObjectId(id), ); @@ -2125,7 +2125,7 @@ export default class ClientApi extends NextApiTemplate { handler: async (req, res, { db: dbPromise }, authData, args) => { const db = await dbPromise; - const users = await db.findObjects(CollectionId.Users, { + const users = await db.findObjects(CollectionId.Users, { xp: { $gt: 0 }, email: { $ne: "totallyrealemail@gmail.com" }, }); @@ -2135,7 +2135,7 @@ export default class ClientApi extends NextApiTemplate { users.map((user) => user.teams.map((id) => new ObjectId(id))).flat(), ); - const teams = await db.findObjects(CollectionId.Teams, { + const teams = await db.findObjects(CollectionId.Teams, { _id: { $in: users .map((user) => user.teams.map((id) => new ObjectId(id))) diff --git a/lib/client/dbinterfaces/DbInterface.ts b/lib/client/dbinterfaces/DbInterface.ts index b0d6147c..fd85de11 100644 --- a/lib/client/dbinterfaces/DbInterface.ts +++ b/lib/client/dbinterfaces/DbInterface.ts @@ -20,21 +20,24 @@ export default interface DbInterface { id: ObjectId, newValues: Partial, ): Promise; - findObjectById( - collection: CollectionId, + findObjectById< + TId extends CollectionId, + TObj extends CollectionIdToType, + >( + collection: TId, id: ObjectId, - ): Promise; - findObject( - collection: CollectionId, + ): Promise; + findObject>( + collection: TId, query: object, - ): Promise; + ): Promise; /** * Type should not be an array! This function returns an array of Type (Type[]). */ - findObjects( - collection: CollectionId, + findObjects>( + collection: TId, query: object, - ): Promise; + ): Promise; countObjects( collection: CollectionId, query: object, diff --git a/lib/client/dbinterfaces/InMemoryDbInterface.ts b/lib/client/dbinterfaces/InMemoryDbInterface.ts index b5e55c71..6bdf5ed0 100644 --- a/lib/client/dbinterfaces/InMemoryDbInterface.ts +++ b/lib/client/dbinterfaces/InMemoryDbInterface.ts @@ -154,21 +154,27 @@ export default class InMemoryDbInterface implements DbInterface { }); } - findObjectById( - collection: CollectionId, + findObjectById< + TId extends CollectionId, + TObj extends CollectionIdToType, + >( + collection: TId, id: ObjectId, - ): Promise { + ): Promise { return this.findObject(collection, { _id: id }); } - findObject( - collection: CollectionId, + findObject< + TId extends CollectionId, + TObj extends CollectionIdToType, + >( + collection: TId, query: object, - ): Promise { + ): Promise { return this.backingDb.collections[collection] .findOne(serialize(query, false)) .then(deserialize) - .then((obj: Type) => { + .then((obj: TObj) => { if (Object.keys(obj).length === 0) { return undefined; } @@ -177,10 +183,13 @@ export default class InMemoryDbInterface implements DbInterface { }); } - findObjects( - collection: CollectionId, + findObjects< + TId extends CollectionId, + TObj extends CollectionIdToType, + >( + collection: TId, query: object, - ): Promise { + ): Promise { return this.backingDb.collections[collection] .find(serialize(query, false)) .fetch() diff --git a/lib/dev/FakeData.ts b/lib/dev/FakeData.ts index 73d47902..d84547df 100644 --- a/lib/dev/FakeData.ts +++ b/lib/dev/FakeData.ts @@ -65,7 +65,7 @@ export async function fillTeamWithFakeUsers( users.push((await fakeUser(teamId, db))._id?.toString()); } - const team = await db.findObjectById( + const team = await db.findObjectById( CollectionId.Teams, new ObjectId(teamId?.toString()), ); diff --git a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/pit/[...pitreportId].tsx b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/pit/[...pitreportId].tsx index 9b8f764b..06a8f576 100644 --- a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/pit/[...pitreportId].tsx +++ b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/pit/[...pitreportId].tsx @@ -308,7 +308,7 @@ export default function PitReportForm(props: { async function getPitreport(id: string) { const db = await getDatabase(); - return await db.findObjectById( + return await db.findObjectById( CollectionId.PitReports, new ObjectId(id), ); diff --git a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/stats.tsx b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/stats.tsx index 276ca4fb..047de81c 100644 --- a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/stats.tsx +++ b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/stats.tsx @@ -188,23 +188,23 @@ export const getServerSideProps: GetServerSideProps = async (context) => { return resolved; } - const reports = await db.findObjects(CollectionId.Reports, { + const reports = await db.findObjects(CollectionId.Reports, { match: { $in: resolved.competition?.matches }, submitted: true, }); - const pitReports = await db.findObjects(CollectionId.PitReports, { + const pitReports = await db.findObjects(CollectionId.PitReports, { _id: { $in: resolved.competition?.pitReports }, }); - const subjectiveReports = await db.findObjects( + const subjectiveReports = await db.findObjects( CollectionId.SubjectiveReports, { match: { $in: resolved.competition?.matches }, }, ); - const picklists = await db.findObjectById( + const picklists = await db.findObjectById( CollectionId.Picklists, new ObjectId(resolved.competition?.picklist), ); diff --git a/pages/[teamSlug]/index.tsx b/pages/[teamSlug]/index.tsx index b08aa2f3..91b79295 100644 --- a/pages/[teamSlug]/index.tsx +++ b/pages/[teamSlug]/index.tsx @@ -596,11 +596,11 @@ export const getServerSideProps: GetServerSideProps = async (context) => { (seasonId) => new ObjectId(seasonId), ); const userIds = resolved.team?.users.map((userId) => new ObjectId(userId)); - const seasons = await db.findObjects(CollectionId.Seasons, { + const seasons = await db.findObjects(CollectionId.Seasons, { _id: { $in: seasonIds }, }); - var users = await db.findObjects(CollectionId.Users, { + var users = await db.findObjects(CollectionId.Users, { _id: { $in: userIds }, }); @@ -614,7 +614,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { const currentSeason = seasons[seasons.length - 1]; var comp = undefined; if (currentSeason) { - comp = await db.findObjectById( + comp = await db.findObjectById( CollectionId.Competitions, new ObjectId( currentSeason.competitions[currentSeason.competitions.length - 1], diff --git a/scripts/loadUsersIntoResend.ts b/scripts/loadUsersIntoResend.ts index 0fb7a027..fdc34a3b 100644 --- a/scripts/loadUsersIntoResend.ts +++ b/scripts/loadUsersIntoResend.ts @@ -10,7 +10,7 @@ async function loadUsersIntoResend() { const db = await getDatabase(); console.log("Finding users..."); - const users = await db.findObjects(CollectionId.Users, {}); + const users = await db.findObjects(CollectionId.Users, {}); console.log(`Saving ${users.length} users to Resend...`); diff --git a/tests/lib/api/ClientApi.test.ts b/tests/lib/api/ClientApi.test.ts index c9187a76..aa8e5eec 100644 --- a/tests/lib/api/ClientApi.test.ts +++ b/tests/lib/api/ClientApi.test.ts @@ -47,7 +47,7 @@ describe(`${ClientApi.name}.${api.requestToJoinTeam.name}`, () => { expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ result: "Already on team" }); - const team = await db.findObjectById(CollectionId.Teams, teamId); + const team = await db.findObjectById(CollectionId.Teams, teamId); expect(team?.requests).toEqual([]); }); @@ -68,7 +68,7 @@ describe(`${ClientApi.name}.${api.requestToJoinTeam.name}`, () => { expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ result: "Success" }); - const team = await db.findObjectById(CollectionId.Teams, teamId); + const team = await db.findObjectById(CollectionId.Teams, teamId); expect(team?.requests).toEqual([user._id!.toString()]); }); @@ -147,10 +147,10 @@ describe(`${ClientApi.name}.${api.handleTeamJoinRequest.name}`, () => { ])), ); - const team = await db.findObjectById(CollectionId.Teams, teamId); + const team = await db.findObjectById(CollectionId.Teams, teamId); expect(team?.users).toEqual([user._id!.toString()]); - const foundUser = await db.findObjectById( + const foundUser = await db.findObjectById( CollectionId.Users, user._id! as any as ObjectId, ); @@ -177,7 +177,7 @@ describe(`${ClientApi.name}.${api.handleTeamJoinRequest.name}`, () => { ])), ); - const team = await db.findObjectById(CollectionId.Teams, teamId); + const team = await db.findObjectById(CollectionId.Teams, teamId); expect(team?.requests).toEqual([]); expect(team?.users).toEqual([]); }); @@ -225,7 +225,7 @@ describe(`${ClientApi.name}.${api.createTeam.name}`, () => { ...(await getTestApiParams(res, { db, user }, ["", "", 1, League.FRC])), ); - const team = await db.findObject(CollectionId.Teams, { + const team = await db.findObject(CollectionId.Teams, { number: 1, league: League.FRC, }); @@ -242,7 +242,7 @@ describe(`${ClientApi.name}.${api.createTeam.name}`, () => { ); const team = res.send.mock.calls[0][0] as Team; // The handler doesn't return a value, so we have to get the team from res - const foundUser = await db.findObjectById( + const foundUser = await db.findObjectById( CollectionId.Users, new ObjectId(user._id!), ); @@ -566,7 +566,7 @@ describe(`${ClientApi.name}.${api.updateUser.name}`, () => { ...(await getTestApiParams(res, { db, user }, [newValues])), ); - const updatedUser = await db.findObjectById( + const updatedUser = await db.findObjectById( CollectionId.Users, new ObjectId(user._id!), ); @@ -593,7 +593,7 @@ describe(`${ClientApi.name}.${api.updateTeam.name}`, () => { )), ); - const updatedTeam = await db.findObjectById( + const updatedTeam = await db.findObjectById( CollectionId.Teams, new ObjectId(team._id!), ); @@ -850,13 +850,13 @@ describe(`${ClientApi.name}.${api.setSlackWebhook.name}`, () => { webhookUrl, ); - const updatedTeam = await db.findObjectById( + const updatedTeam = await db.findObjectById( CollectionId.Teams, new ObjectId(team._id!), ); expect(updatedTeam?.slackWebhook).not.toBe(undefined); - const webhook = await db.findObjectById( + const webhook = await db.findObjectById( CollectionId.Webhooks, new ObjectId(updatedTeam!.slackWebhook!), ); @@ -892,13 +892,13 @@ describe(`${ClientApi.name}.${api.setSlackWebhook.name}`, () => { webhookUrl, ); - const updatedTeam = await db.findObjectById( + const updatedTeam = await db.findObjectById( CollectionId.Teams, new ObjectId(team._id!), ); expect(updatedTeam?.slackWebhook).toEqual(webhook._id!.toString()); - const updatedWebhook = await db.findObjectById( + const updatedWebhook = await db.findObjectById( CollectionId.Webhooks, new ObjectId(updatedTeam!.slackWebhook!), );