Skip to content

Commit

Permalink
feat(getConsoleIds): add new query params
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland committed May 24, 2024
1 parent 3600962 commit 3fe1c71
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/console/getConsoleIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setupServer } from "msw/node";
import { apiBaseUrl } from "../utils/internal";
import { buildAuthorization } from "../utils/public";
import { getConsoleIds } from "./getConsoleIds";
import type { ConsoleId, GetConsoleIdsResponse } from "./models";
import type { FetchedSystem, GetConsoleIdsResponse } from "./models";

const server = setupServer();

Expand Down Expand Up @@ -34,18 +34,24 @@ describe("Function: getConsoleIds", () => {
Name: "Mega Drive",
IconURL:
"https://static.retroachievements.org/assets/images/system/md.png",
Active: true,
IsGameSystem: true,
},
{
ID: "2",
Name: "Nintendo 64",
IconURL:
"https://static.retroachievements.org/assets/images/system/n64.png",
Active: true,
IsGameSystem: true,
},
{
ID: "3",
Name: "SNES",
IconURL:
"https://static.retroachievements.org/assets/images/system/snes.png",
Active: false,
IsGameSystem: false,
},
];

Expand All @@ -59,24 +65,30 @@ describe("Function: getConsoleIds", () => {
const response = await getConsoleIds(authorization);

// ASSERT
const expectedResponse: ConsoleId[] = [
const expectedResponse: FetchedSystem[] = [
{
id: 1,
name: "Mega Drive",
iconUrl:
"https://static.retroachievements.org/assets/images/system/md.png",
active: true,
isGameSystem: true,
},
{
id: 2,
name: "Nintendo 64",
iconUrl:
"https://static.retroachievements.org/assets/images/system/n64.png",
active: true,
isGameSystem: true,
},
{
id: 3,
name: "SNES",
iconUrl:
"https://static.retroachievements.org/assets/images/system/snes.png",
active: false,
isGameSystem: false,
},
];

Expand Down
32 changes: 27 additions & 5 deletions src/console/getConsoleIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
serializeProperties,
} from "../utils/internal";
import type { AuthObject } from "../utils/public";
import type { ConsoleId, GetConsoleIdsResponse } from "./models";
import type { FetchedSystem, GetConsoleIdsResponse } from "./models";

/**
* A call to this function will retrieve the complete list
Expand All @@ -15,6 +15,12 @@ import type { ConsoleId, GetConsoleIdsResponse } from "./models";
* @param authorization An object containing your userName and webApiKey.
* This can be constructed with `buildAuthorization()`.
*
* @param payload.shouldOnlyRetrieveActiveSystems If true, only systems that
* officially support achievements will be returned.
*
* @param payload.shouldOnlyRetrieveGameSystems If true, events and hubs will
* not be returned.
*
* @example
* ```
* const consoleIds = await getConsoleIds(authorization);
Expand All @@ -26,17 +32,33 @@ import type { ConsoleId, GetConsoleIdsResponse } from "./models";
* {
* id: "1",
* name: "Mega Drive",
* iconUrl: "https://static.retroachievements.org/assets/images/system/md.png"
* iconUrl: "https://static.retroachievements.org/assets/images/system/md.png",
* active: true,
* isGameSystem: true
* }
* ```
*/
export const getConsoleIds = async (
authorization: AuthObject
): Promise<ConsoleId[]> => {
authorization: AuthObject,
payload?: {
shouldOnlyRetrieveActiveSystems: boolean;
shouldOnlyRetrieveGameSystems: boolean;
}
): Promise<FetchedSystem[]> => {
let callPayload: Record<string, any> | undefined;

if (payload?.shouldOnlyRetrieveActiveSystems) {
callPayload = { ...callPayload, a: 1 };
}
if (payload?.shouldOnlyRetrieveGameSystems) {
callPayload = { ...callPayload, g: 1 };
}

const url = buildRequestUrl(
apiBaseUrl,
"/API_GetConsoleIDs.php",
authorization
authorization,
callPayload
);

const rawResponse = await call<GetConsoleIdsResponse>({ url });
Expand Down
5 changes: 0 additions & 5 deletions src/console/models/console-id.model.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/console/models/fetched-system.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface FetchedSystem {
id: number;
name: string;
iconUrl: string;
active: boolean;
isGameSystem: boolean;
}
2 changes: 2 additions & 0 deletions src/console/models/get-console-ids-response.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export type GetConsoleIdsResponse = readonly {
ID: string;
Name: string;
IconURL: string;
Active: boolean;
IsGameSystem: boolean;
}[];
2 changes: 1 addition & 1 deletion src/console/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./console-id.model";
export * from "./fetched-system.model";
export * from "./game-list.model";
export * from "./get-console-ids-response.model";
export * from "./get-game-list-response.model";

0 comments on commit 3fe1c71

Please sign in to comment.