trans-history: concepto multiidioma (helper de concepto compartido)
Extrae la lógica de concepto traducible a lib/tx-concept.ts (buildConcept + purchasedPD + SERVICE_CONCEPT) y la reutilizan points-history y trans-history. La columna Concepto de trans-history ahora se traduce (reusa History.points.concept.*) en vez de mostrar el product_name en español. Corrige también la sombra de variable en PlatformBox (map t -> tx). Verificado con la cuenta 15. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { RowDataPacket } from 'mysql2'
|
||||
import { db, DB } from './db'
|
||||
import { buildConcept } from './tx-concept'
|
||||
|
||||
/** Una transacción de pago (Stripe o SumUp) registrada en home_stripelog. */
|
||||
export interface PaymentTx {
|
||||
@@ -8,7 +9,10 @@ export interface PaymentTx {
|
||||
status: 'PAID' | 'PENDING'
|
||||
createdAt: Date
|
||||
amount: number // importe en €
|
||||
concept: string
|
||||
// Concepto traducible (clave + args) con reserva de texto libre.
|
||||
conceptKey: string | null
|
||||
conceptArgs: Record<string, string | number>
|
||||
conceptRaw: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,18 +24,28 @@ export async function getPaymentTransactions(accountId: number, limit = 200): Pr
|
||||
if (!accountId) return []
|
||||
try {
|
||||
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
||||
"SELECT session_id, product_name, amount, mode, fulfilled, timestamp FROM home_stripelog " +
|
||||
'SELECT session_id, product_name, character_name, amount, mode, service, metadata, fulfilled, timestamp FROM home_stripelog ' +
|
||||
"WHERE account_id = ? AND mode IN ('sumup', 'test', 'live') ORDER BY timestamp DESC LIMIT ?",
|
||||
[accountId, limit],
|
||||
)
|
||||
return rows.map((r) => ({
|
||||
id: String(r.session_id || ''),
|
||||
platform: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
||||
status: r.fulfilled ? 'PAID' : 'PENDING',
|
||||
createdAt: new Date(r.timestamp),
|
||||
amount: Number(r.amount),
|
||||
concept: String(r.product_name || '—'),
|
||||
}))
|
||||
return rows.map((r) => {
|
||||
const c = buildConcept(
|
||||
String(r.product_name || '—'),
|
||||
r.service ? String(r.service) : null,
|
||||
String(r.character_name || ''),
|
||||
r.metadata ? String(r.metadata) : null,
|
||||
)
|
||||
return {
|
||||
id: String(r.session_id || ''),
|
||||
platform: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
||||
status: r.fulfilled ? 'PAID' : 'PENDING',
|
||||
createdAt: new Date(r.timestamp),
|
||||
amount: Number(r.amount),
|
||||
conceptKey: c.conceptKey,
|
||||
conceptArgs: c.conceptArgs,
|
||||
conceptRaw: c.conceptRaw,
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user