feat(trucks): site_id column and site/truck helpers
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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 ?? ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user