fix(loyalty): align /locations endpoint shape with template bindings
The shared loyalty list partials (pins, cards, transactions, devices,
admin merchant detail) bind store filter dropdowns to
loc.store_id/loc.store_name, but the /merchants/loyalty/locations and
/admin/loyalty/merchants/{id}/locations endpoints were returning
{id, name, code}. Result: every store-filter dropdown was silently
empty across the loyalty module.
Switch both endpoints to {store_id, store_name, store_code}, matching
the shape used everywhere else (analytics, location stats). Storefront
locations come from a different code path and are unaffected.
Drop the temporary normalizer in the devices Alpine factory now that
the endpoint speaks the right shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -95,15 +95,9 @@ function loyaltyDevicesList(config) {
|
||||
async loadLocations() {
|
||||
try {
|
||||
const response = await apiClient.get(locationsPrefix + '/locations');
|
||||
if (!response) return;
|
||||
const raw = Array.isArray(response) ? response : (response.locations || []);
|
||||
// Endpoint returns {id, name, code}; templates bind to store_id/store_name.
|
||||
// Normalize so callers don't have to care about either shape.
|
||||
this.locations = raw.map(loc => ({
|
||||
store_id: loc.store_id ?? loc.id,
|
||||
store_name: loc.store_name ?? loc.name,
|
||||
store_code: loc.store_code ?? loc.code,
|
||||
}));
|
||||
if (response) {
|
||||
this.locations = Array.isArray(response) ? response : (response.locations || []);
|
||||
}
|
||||
} catch (error) {
|
||||
loyaltyDevicesListLog.warn('Failed to load locations:', error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user