/** * Query keys. * * Every Fiesta list endpoint requires a scoping id and 400s without one, so the * scoping id is part of the key by construction. That is not a caching nicety: * it is what stops one tenant's cached rows being served to another after a * switch. */ export const queryKeys = { /** Delivery partners — the companies that supply riders. */ partners: { all: ['partners'] as const, inRegion: (applocationid: number) => ['partners', 'region', applocationid] as const, locations: (partnerid: number) => ['partners', 'locations', partnerid] as const, logs: (partnerid: number, fromdate: string, todate: string) => ['partners', 'logs', partnerid, fromdate, todate] as const, }, /** The delivery regions a partner can cover. */ regions: { all: ['regions'] as const }, uploads: { all: ['uploads'] as const, list: (tenantid: number, locationid: number) => [...queryKeys.uploads.all, 'list', tenantid, locationid] as const, }, tenants: { all: ['tenants'] as const, byId: (tenantid: number) => [...queryKeys.tenants.all, 'byId', tenantid] as const, list: (params: Record = {}) => [...queryKeys.tenants.all, 'list', params] as const, appCategories: () => [...queryKeys.tenants.all, 'appCategories'] as const, approval: (status: string, keyword: string) => [...queryKeys.tenants.all, 'approval', status, keyword] as const, locations: (tenantid: number) => [...queryKeys.tenants.all, 'locations', tenantid] as const, search: (keyword: string) => [...queryKeys.tenants.all, 'search', keyword] as const, }, catalogue: { all: ['catalogue'] as const, products: (params: Record) => [...queryKeys.catalogue.all, 'products', params] as const, brands: () => [...queryKeys.catalogue.all, 'brands'] as const, categories: (brand: string) => [...queryKeys.catalogue.all, 'categories', brand] as const, importedRefs: (tenantid: number) => [...queryKeys.catalogue.all, 'imported', tenantid] as const, product: (brand: string, sku: string) => [...queryKeys.catalogue.all, 'product', brand, sku] as const, }, products: { all: ['products'] as const, byLocation: (tenantid: number, locationid: number, page: number) => [...queryKeys.products.all, 'location', tenantid, locationid, page] as const, categories: (tenantid: number) => [...queryKeys.products.all, 'categories', tenantid] as const, subCategories: (tenantid: number, categoryid: number) => [...queryKeys.products.all, 'subcategories', tenantid, categoryid] as const, count: (tenantid: number) => [...queryKeys.products.all, 'count', tenantid] as const, tenantCategories: (tenantid: number) => [...queryKeys.products.all, 'tenantcategories', tenantid] as const, }, insights: { all: ['insights'] as const, orders: (tenantid: number) => [...queryKeys.insights.all, 'orders', tenantid] as const, locations: (tenantid: number) => [...queryKeys.insights.all, 'locations', tenantid] as const, deliveries: (tenantid: number) => [...queryKeys.insights.all, 'deliveries', tenantid] as const, posSales: (locationid: number) => [...queryKeys.insights.all, 'pos-sales', locationid] as const, posHealth: (locationid: number) => [...queryKeys.insights.all, 'pos-health', locationid] as const, posSalesSummary: (locationid: number, range: Record) => [...queryKeys.insights.all, 'pos-summary', locationid, range] as const, posBills: (locationid: number, params: Record) => [...queryKeys.insights.all, 'pos-bills', locationid, params] as const, orderList: (params: Record) => [...queryKeys.insights.all, 'order-list', params] as const, deliveryList: (params: Record) => [...queryKeys.insights.all, 'delivery-list', params] as const, /** Keyed on the delivery region, which is what the endpoint filters on. */ riders: (applocationid: number) => [...queryKeys.insights.all, 'riders', applocationid] as const, /** The directory — everyone, working today or not. */ riderRoster: (tenantid: number) => [...queryKeys.insights.all, 'rider-roster', tenantid] as const, riderShifts: (applocationid: number) => [...queryKeys.insights.all, 'rider-shifts', applocationid] as const, partners: (applocationid: number) => [...queryKeys.insights.all, 'partners', applocationid] as const, }, people: { all: ['people'] as const, staff: (tenantid: number) => [...queryKeys.people.all, 'staff', tenantid] as const, posUsers: (tenantid: number, locationid: number) => [...queryKeys.people.all, 'pos-users', tenantid, locationid] as const, posRoles: () => [...queryKeys.people.all, 'pos-roles'] as const, shifts: (tenantid: number, locationid: number) => [...queryKeys.people.all, 'shifts', tenantid, locationid] as const, }, customers: { all: ['customers'] as const, list: (params: Record) => [...queryKeys.customers.all, 'list', params] as const, }, stock: { all: ['stock'] as const, requests: (params: Record) => [...queryKeys.stock.all, 'requests', params] as const, statement: (tenantid: number, locationid: number, params: Record) => [...queryKeys.stock.all, 'statement', tenantid, locationid, params] as const, }, } as const;