feat(api): add customer accounts with live summary and append-only ledger
One balance row per (user, kind, currency): available and frozen carry the platform base currency, points carries none. Monetary and points rows use separate partial unique indexes because a plain UNIQUE lets NULL repeat. Balance changes go through transactional primitives that debits guard with a conditional update, credits add atomically, and freeze/release move both sides in one transaction after locking rows by primary key. Every change appends an immutable entry holding its resulting balance. Registration and a migration backfill create the zero rows; GET /api/me/stats is the only public surface and no endpoint mutates a balance. The mall buyer center and points page drop the USER_STATS fixture for the shared contract; the fixture stays exported so the fixed-data adapter can still serve the account domain as a rollback path. Implements openspec change add-customer-accounts.
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import type { AccountSummary } from "@vmall/shared";
|
||||
import { t as pick } from "@vmall/shared";
|
||||
import { INTEGRAL_PRODUCTS, USER_STATS } from "~/mock/data";
|
||||
// The catalog stays on fixtures until the points-mall change lands; the points
|
||||
// balance itself is live.
|
||||
import { INTEGRAL_PRODUCTS } from "~/mock/data";
|
||||
|
||||
const { locale, t } = useI18n();
|
||||
const { $api } = useNuxtApp();
|
||||
const session = useSessionStore();
|
||||
const stats = ref<AccountSummary | null>(null);
|
||||
const redeemed = ref<Set<string>>(new Set());
|
||||
|
||||
async function loadStats(): Promise<void> {
|
||||
if (!session.isLoggedIn) {
|
||||
stats.value = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
stats.value = await $api.getAccountSummary();
|
||||
} catch {
|
||||
stats.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
const breadcrumb = computed(() => [
|
||||
{ label: t("stores.breadcrumbHome"), to: "/" },
|
||||
{ label: t("marketing.integralBreadcrumb") },
|
||||
@@ -19,7 +36,10 @@ function isRedeemed(id: string): boolean {
|
||||
return redeemed.value.has(id);
|
||||
}
|
||||
|
||||
onMounted(() => session.hydrate());
|
||||
onMounted(() => {
|
||||
session.hydrate();
|
||||
void loadStats();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -35,7 +55,7 @@ onMounted(() => session.hydrate());
|
||||
<div>
|
||||
<p class="account-name">{{ session.user?.display_name }}</p>
|
||||
<p class="points-label">{{ t("marketing.pointsBalance") }}</p>
|
||||
<strong class="account-points">{{ USER_STATS.points }}</strong>
|
||||
<strong class="account-points">{{ stats ? stats.points : t("common.loading") }}</strong>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
|
||||
Reference in New Issue
Block a user