// The Stall screen's own call (change C11): the packets assigned to me, across stations. Nobody picks a station on // the Stall screen; each card carries the station the supervisor picked when assigning. import { api } from "./client"; import { qs } from "./query"; import { normaliseCard, type ShopCard } from "./shop"; import { normaliseFacets, type BoardQuery, type Facets } from "./types"; /** A stall card: the shop card plus the station it is assigned to. */ export interface StallCard extends ShopCard { station_id: number | null; station_name: string | null; } /** GET /api/stall/mine: the stall board shape, without a station. */ export interface StallMine { mine: StallCard[]; submitted: StallCard[]; facets?: Facets; } function cards(raw: unknown): StallCard[] { if (!Array.isArray(raw)) return []; return (raw as Array & ShopCard>).map((c) => { const card = normaliseCard(c); const id = c.station_id ?? c.station?.id ?? null; const name = c.station_name ?? c.station?.name ?? null; // The card's own station line reads `station`; fill it from the flat fields when the server sends only those. const station = card.station ?? (id !== null ? { id, name: name ?? "" } : null); return { ...card, station, station_id: id, station_name: name }; }); } /** The find bar's query applies; `me` and the session decide whose packets. */ export async function getStallMine(q: BoardQuery = {}, signal?: AbortSignal): Promise { const raw = await api.get | null>(`/api/stall/mine${qs({ ...q })}`, signal); const facets = normaliseFacets(raw?.facets); return { mine: cards(raw?.mine), submitted: cards(raw?.submitted), ...(facets ? { facets } : {}) }; } export const stallApi = { getStallMine };