From d107d4c5e71ba88b01fc40963013d57e450ce69b Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Fri, 24 May 2024 15:30:35 -0400 Subject: [PATCH] feat(getConsoleIds): add new query params (#95) --- src/console/getConsoleIds.test.ts | 16 ++++++++-- src/console/getConsoleIds.ts | 32 ++++++++++++++++--- src/console/models/console-id.model.ts | 5 --- src/console/models/fetched-system.model.ts | 7 ++++ .../models/get-console-ids-response.model.ts | 2 ++ src/console/models/index.ts | 2 +- 6 files changed, 51 insertions(+), 13 deletions(-) delete mode 100644 src/console/models/console-id.model.ts create mode 100644 src/console/models/fetched-system.model.ts diff --git a/src/console/getConsoleIds.test.ts b/src/console/getConsoleIds.test.ts index 0b614bf..fec7b02 100644 --- a/src/console/getConsoleIds.test.ts +++ b/src/console/getConsoleIds.test.ts @@ -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(); @@ -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, }, ]; @@ -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, }, ]; diff --git a/src/console/getConsoleIds.ts b/src/console/getConsoleIds.ts index bb6f074..0c9e511 100644 --- a/src/console/getConsoleIds.ts +++ b/src/console/getConsoleIds.ts @@ -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 @@ -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); @@ -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 => { + authorization: AuthObject, + payload?: { + shouldOnlyRetrieveActiveSystems: boolean; + shouldOnlyRetrieveGameSystems: boolean; + } +): Promise => { + let callPayload: Record | 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({ url }); diff --git a/src/console/models/console-id.model.ts b/src/console/models/console-id.model.ts deleted file mode 100644 index 8ffaf4e..0000000 --- a/src/console/models/console-id.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface ConsoleId { - id: number; - name: string; - iconUrl: string; -} diff --git a/src/console/models/fetched-system.model.ts b/src/console/models/fetched-system.model.ts new file mode 100644 index 0000000..f6e23c2 --- /dev/null +++ b/src/console/models/fetched-system.model.ts @@ -0,0 +1,7 @@ +export interface FetchedSystem { + id: number; + name: string; + iconUrl: string; + active: boolean; + isGameSystem: boolean; +} diff --git a/src/console/models/get-console-ids-response.model.ts b/src/console/models/get-console-ids-response.model.ts index 3f06f86..f53857b 100644 --- a/src/console/models/get-console-ids-response.model.ts +++ b/src/console/models/get-console-ids-response.model.ts @@ -2,4 +2,6 @@ export type GetConsoleIdsResponse = readonly { ID: string; Name: string; IconURL: string; + Active: boolean; + IsGameSystem: boolean; }[]; diff --git a/src/console/models/index.ts b/src/console/models/index.ts index 5af7a84..c5d95b1 100644 --- a/src/console/models/index.ts +++ b/src/console/models/index.ts @@ -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";