-
Notifications
You must be signed in to change notification settings - Fork 0
/
allDataForShow.ts
35 lines (33 loc) · 1.29 KB
/
allDataForShow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { QueryCommand } from "@aws-sdk/lib-dynamodb";
import { StructuredQuery } from "./index";
import * as Stat from "../entity/stat";
import { statGroupFromItems } from "../entity/stat";
import * as Show from "../entity/show";
import * as PlayerAppearance from "../entity/playerAppearance";
type StatGroup = Partial<Record<Stat.StatType, Stat.Stat[]>>;
export function allDataForShow(showId: Show.ShowId): StructuredQuery<{
show?: Show.Show;
players: PlayerAppearance.PlayerAppearance[];
stats: StatGroup;
}> {
return {
query: new QueryCommand({
TableName: "inventory",
IndexName: "gsi1",
KeyConditionExpression: "gsi1pk = :gsi1pk",
ExpressionAttributeValues: {
":gsi1pk": `slug#${showId}`,
},
}),
parser: (items: Record<string, any>[]) => {
const show = items.find((item) => item.entity_type === "show");
return {
show: show ? Show.fromStorage(show) : undefined,
players: items
.filter((item) => item.entity_type === "player_appearance")
.map((appearanceStorage) => PlayerAppearance.fromStorage(appearanceStorage)),
stats: statGroupFromItems(items),
};
},
};
}