Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Created September 22, 2023 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thawkin3/9a7d3bba991755b5b83bb4f31095d659 to your computer and use it in GitHub Desktop.
Save thawkin3/9a7d3bba991755b5b83bb4f31095d659 to your computer and use it in GitHub Desktop.
Ping Pong Ranking App - Player History
type Inputs = {
playerID: string;
};
type Match = {
matchID: string;
winnerID: string;
loserID: string;
};
type Matches = {
[key: string]: Match;
};
type FormattedMatch = {
matchID: string;
opponent: string;
result: "Won" | "Lost";
};
export async function handler({ playerID }: Inputs) {
const allMatches: Matches = await Zipper.storage.getAll();
const matchesArray: Match[] = Object.values(allMatches);
const playerMatches = matchesArray.filter((match: Match) => {
return playerID === match.winnerID || playerID === match.loserID;
});
const formattedPlayerMatches = playerMatches.map((match: Match) => {
const formattedMatch: FormattedMatch = {
matchID: match.matchID,
opponent: playerID === match.winnerID ? match.loserID : match.winnerID,
result: playerID === match.winnerID ? "Won" : "Lost",
};
return formattedMatch;
});
return formattedPlayerMatches;
}
export const config: Zipper.HandlerConfig = {
description: {
title: "Player History",
subtitle: "See match history for the selected player",
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment