Files
orion/app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
Samir Boulahtit 4a1f71a312
Some checks failed
CI / ruff (push) Successful in 11s
CI / validate (push) Successful in 26s
CI / dependency-scanning (push) Successful in 32s
CI / pytest (push) Failing after 3h8m55s
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
fix(loyalty): resolve critical production readiness issues
- Add pessimistic locking (SELECT FOR UPDATE) on card write operations
  to prevent race conditions in stamp_service and points_service
- Replace 16 console.log/error/warn calls with LogConfig.createLogger()
  in 3 storefront JS files (dashboard, history, enroll)
- Delete all stale lu.json locale files across 8 modules (lb is the
  correct ISO 639-1 code for Luxembourgish)
- Update architecture rules and docs to reference lb.json not lu.json
- Add production-readiness.md report for loyalty module

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 23:18:18 +01:00

93 lines
3.0 KiB
JavaScript

// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js
// Customer loyalty dashboard
const loyaltyDashboardLog = window.LogConfig.loggers.loyaltyDashboard || window.LogConfig.createLogger('loyaltyDashboard');
function customerLoyaltyDashboard() {
return {
...storefrontLayoutData(),
// Data
card: null,
program: null,
rewards: [],
transactions: [],
locations: [],
// Wallet
walletUrls: { google_wallet_url: null, apple_wallet_url: null },
// UI state
loading: false,
showBarcode: false,
async init() {
loyaltyDashboardLog.info('Customer loyalty dashboard initializing...');
await this.loadData();
},
async loadData() {
this.loading = true;
try {
await Promise.all([
this.loadCard(),
this.loadTransactions()
]);
} catch (error) {
loyaltyDashboardLog.error('Failed to load loyalty data:', error);
} finally {
this.loading = false;
}
},
async loadCard() {
try {
const response = await apiClient.get('/storefront/loyalty/card');
if (response) {
this.card = response.card;
this.program = response.program;
this.rewards = response.program?.points_rewards || [];
this.locations = response.locations || [];
this.walletUrls = response.wallet_urls || { google_wallet_url: null, apple_wallet_url: null };
loyaltyDashboardLog.info('Loyalty card loaded:', this.card?.card_number);
}
} catch (error) {
if (error.status === 404) {
loyaltyDashboardLog.info('No loyalty card found');
this.card = null;
} else {
throw error;
}
}
},
async loadTransactions() {
try {
const response = await apiClient.get('/storefront/loyalty/transactions?limit=10');
if (response && response.transactions) {
this.transactions = response.transactions;
}
} catch (error) {
loyaltyDashboardLog.warn('Failed to load transactions:', error.message);
}
},
formatNumber(num) {
if (num == null) return '0';
return new Intl.NumberFormat('en-US').format(num);
},
formatDate(dateString) {
if (!dateString) return '-';
try {
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} catch (e) {
return dateString;
}
}
};
}