Skip to content

Commit

Permalink
Now checks that api method actually exist!
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodellosso committed Dec 19, 2024
1 parent 3994adb commit 3c9f9af
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/api/ApiLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace ApiLib {
};

export abstract class ApiTemplate<TDependencies> {
[route: string]: any;
// [route: string]: any;

private initSegment(segment: Segment<any>, subUrl: string) {
for (const [key, value] of Object.entries(segment)) {
Expand All @@ -194,7 +194,7 @@ namespace ApiLib {
}

protected init() {
this.initSegment(this as Segment<any>, "");
this.initSegment(this as unknown as Segment<any>, "");
}

/**
Expand Down Expand Up @@ -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<any, any, TDependencies, any> | undefined;

Expand Down
7 changes: 0 additions & 7 deletions lib/api/ClientApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export default class ClientApi extends ApiLib.ApiTemplate<ApiDependencies> {
await db
).findObjectById<Team>(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");
}
Expand All @@ -99,8 +95,6 @@ export default class ClientApi extends ApiLib.ApiTemplate<ApiDependencies> {
(await userPromise)?._id?.toString(),
]);

console.log("Request is valid!");

await (
await db
).updateObjectById(CollectionId.Teams, new ObjectId(teamId), team);
Expand Down Expand Up @@ -521,7 +515,6 @@ export default class ClientApi extends ApiLib.ApiTemplate<ApiDependencies> {
compId,
);

console.log(result);
return res.status(200).send({ result: result });
},
});
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/api/ApiLib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 3c9f9af

Please sign in to comment.