From 3c9f9af977919f7955abfb0873d6ed20f0806f71 Mon Sep 17 00:00:00 2001 From: renatodellosso Date: Wed, 18 Dec 2024 21:03:28 -0500 Subject: [PATCH] Now checks that api method actually exist! --- lib/api/ApiLib.ts | 6 +++--- lib/api/ClientApi.ts | 7 ------- tests/lib/api/ApiLib.test.ts | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/api/ApiLib.ts b/lib/api/ApiLib.ts index 79fe7875..5ae15f78 100644 --- a/lib/api/ApiLib.ts +++ b/lib/api/ApiLib.ts @@ -171,7 +171,7 @@ namespace ApiLib { }; export abstract class ApiTemplate { - [route: string]: any; + // [route: string]: any; private initSegment(segment: Segment, subUrl: string) { for (const [key, value] of Object.entries(segment)) { @@ -194,7 +194,7 @@ namespace ApiLib { } protected init() { - this.initSegment(this as Segment, ""); + this.initSegment(this as unknown as Segment, ""); } /** @@ -232,7 +232,7 @@ namespace ApiLib { try { const route = path.reduce( - (segment, route) => segment[route], + (segment, route) => Object(segment)[route], this.api, ) as unknown as Route | undefined; diff --git a/lib/api/ClientApi.ts b/lib/api/ClientApi.ts index 322a73d4..cdfa543e 100644 --- a/lib/api/ClientApi.ts +++ b/lib/api/ClientApi.ts @@ -82,10 +82,6 @@ export default class ClientApi extends ApiLib.ApiTemplate { await db ).findObjectById(CollectionId.Teams, new ObjectId(teamId)); - console.log( - `${(await userPromise)?.name} requested to join ${team?.league} ${team?.number}`, - ); - if (!team) { return res.error(404, "Team not found"); } @@ -99,8 +95,6 @@ export default class ClientApi extends ApiLib.ApiTemplate { (await userPromise)?._id?.toString(), ]); - console.log("Request is valid!"); - await ( await db ).updateObjectById(CollectionId.Teams, new ObjectId(teamId), team); @@ -521,7 +515,6 @@ export default class ClientApi extends ApiLib.ApiTemplate { compId, ); - console.log(result); return res.status(200).send({ result: result }); }, }); diff --git a/tests/lib/api/ApiLib.test.ts b/tests/lib/api/ApiLib.test.ts index 76fec661..9faee07b 100644 --- a/tests/lib/api/ApiLib.test.ts +++ b/tests/lib/api/ApiLib.test.ts @@ -86,7 +86,7 @@ test(`ApiLib.${ApiLib.ApiTemplate.name}.init: Sets subUrl`, () => { ); }); -test(`ApiLib.${ApiLib.ApiTemplate.prototype.name}.init: Sets caller`, async () => { +test(`ApiLib.${ApiLib.ApiTemplate.name}.init: Sets caller`, async () => { expect(clientApi.segment.routeWithPresetCaller.call).toBeDefined(); });