feat(trucks): site_id column and site/truck helpers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 11:44:37 +08:00
co-authored by Claude Sonnet 5.5
parent fd7a55337f
commit 867b725262
9 changed files with 105 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
export function trucksForSite<T extends { site_id: string | null }>(trucks: T[], siteId: string): T[] {
if (!siteId) return trucks
return trucks.filter(t => t.site_id === null || t.site_id === siteId)
}
export function siteForTruck(
trucks: { id: string; site_id: string | null }[],
truckId: string | null | undefined,
): string | null {
if (!truckId) return null
return trucks.find(t => t.id === truckId)?.site_id ?? null
}
+5
View File
@@ -31,3 +31,8 @@ export function resolveZoneToken(args: {
}
return null
}
export function siteIdForToken(sites: SiteOption[], token: string | null): string {
if (!token) return ''
return sites.find(s => s.zones.some(z => z.qr_code_token === token))?.id ?? ''
}