Skip to content

Commit

Permalink
feat(getGameInfoAndUserProgress): add new query param for highest awa…
Browse files Browse the repository at this point in the history
…rd metadata (#96)
  • Loading branch information
wescopeland authored May 24, 2024
1 parent f7427fa commit 340b195
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/user/getGameInfoAndUserProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import type {
* @param payload.username The user for which to retrieve the
* game progress for.
*
* @param payload.shouldIncludeHighestAwardMetadata Include a "HighestAwardKind"
* and a "HighestAwardDate" for the given user and game ID.
*
* @example
* ```
* const gameInfoAndUserProgress = await getGameInfoAndUserProgress(
Expand Down Expand Up @@ -87,18 +90,27 @@ import type {
*/
export const getGameInfoAndUserProgress = async (
authorization: AuthObject,
payload: { gameId: ID; username: string }
payload: {
gameId: ID;
username: string;
shouldIncludeHighestAwardMetadata?: boolean;
}
): Promise<GameInfoAndUserProgress> => {
const { gameId, username } = payload;
const { gameId, username, shouldIncludeHighestAwardMetadata } = payload;

const params: Record<string, any> = {
g: gameId,
u: username,
};
if (shouldIncludeHighestAwardMetadata) {
params.a = 1;
}

const url = buildRequestUrl(
apiBaseUrl,
"/API_GetGameInfoAndUserProgress.php",
authorization,
{
g: gameId,
u: username,
}
params
);

const rawResponse = await call<GetGameInfoAndUserProgressResponse>({ url });
Expand Down
8 changes: 8 additions & 0 deletions src/user/models/game-info-and-user-progress.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ export interface GameInfoAndUserProgress extends GameExtended {
numAwardedToUserHardcore: number;
userCompletion: string;
userCompletionHardcore: string;

highestAwardKind?:
| "mastered"
| "completed"
| "beaten-hardcore"
| "beaten-softcore"
| null;
highestAwardDate?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ export interface GetGameInfoAndUserProgressResponse
NumAwardedToUserHardcore: number;
UserCompletion: string;
UserCompletionHardcore: string;

HighestAwardKind?:
| "mastered"
| "completed"
| "beaten-hardcore"
| "beaten-softcore"
| null;
HighestAwardDate?: string;
}

0 comments on commit 340b195

Please sign in to comment.