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:
2026-07-14 19:35:18 +00:00
parent b2e7ab1b88
commit 19d3c43a76
4 changed files with 96 additions and 63 deletions
+7 -7
View File
@@ -73,22 +73,22 @@ async function PlatformBox({
<th>{t('trans.thCreatedAt')}</th>
<th>{t('trans.thAmount')}</th>
</tr>
{txs.map((t) => (
<tr key={t.id}>
{txs.map((tx) => (
<tr key={tx.id}>
<td className="long-td">
<span>{t.id}</span>
<span>{tx.id}</span>
</td>
<td>
<StatusBadge status={t.status} />
<StatusBadge status={tx.status} />
</td>
<td className="responsive-td">
<span>{t.concept}</span>
<span>{tx.conceptKey ? t(`points.concept.${tx.conceptKey}`, tx.conceptArgs) : tx.conceptRaw}</span>
</td>
<td>
<span>{fmt(t.createdAt)}</span>
<span>{fmt(tx.createdAt)}</span>
</td>
<td>
<span>{t.amount.toFixed(2)} </span>
<span>{tx.amount.toFixed(2)} </span>
</td>
</tr>
))}
+7 -46
View File
@@ -1,5 +1,6 @@
import type { RowDataPacket } from 'mysql2'
import { db, DB } from './db'
import { buildConcept, purchasedPD } from './tx-concept'
/**
* Un movimiento del historial de PD/PV. Los textos visibles se devuelven como
@@ -19,19 +20,6 @@ export interface PointsMovement {
status: 'delivered' | 'pending' | 'credited'
}
/** Slug de servicio (home_stripelog.service) -> clave de concepto traducible. */
const SERVICE_CONCEPT: Record<string, string> = {
rename: 'rename',
customize: 'customize',
'change-race': 'changeRace',
'change-faction': 'changeFaction',
'level-up': 'levelUp',
gold: 'gold',
transfer: 'transfer',
'restore-item': 'restoreItem',
'send-gift': 'sendGift',
}
/** Saldos actuales de PD y PV de una cuenta de juego. */
export async function getPointsBalances(accountId: number): Promise<{ dp: number; pv: number }> {
if (!accountId) return { dp: 0, pv: 0 }
@@ -46,21 +34,6 @@ export async function getPointsBalances(accountId: number): Promise<{ dp: number
}
}
/** PD acreditados por un pago (si es una compra de PD), o null si es un servicio/ítem. */
function purchasedPD(productName: string, service: string | null, metadata: string | null): number | null {
const m = /(\d+)\s*PD\b/i.exec(productName || '')
if (m) return Number(m[1])
if (service === 'dpoints') {
try {
const p = metadata ? JSON.parse(metadata).points : null
return p ? Number(p) : null
} catch {
return null
}
}
return null
}
/**
* Historial unificado de PD/PV de una cuenta, combinando las fuentes reales:
* - `home_stripelog`: pagos por **Stripe** (mode test/live) y **SumUp** (mode sumup).
@@ -82,27 +55,15 @@ export async function getPointsHistory(accountId: number, limit = 100): Promise<
for (const r of rows) {
const service = r.service ? String(r.service) : null
const productName = String(r.product_name || '—')
const pd = purchasedPD(productName, service, r.metadata ? String(r.metadata) : null)
// Concepto traducible: compra de PD -> "{n} PD"; servicio conocido ->
// "{etiqueta}: {personaje}"; en otro caso, texto libre heredado.
let conceptKey: string | null = null
let conceptArgs: Record<string, string | number> = {}
if (pd != null && (service === 'dpoints' || service === null)) {
conceptKey = 'pd'
conceptArgs = { n: pd }
} else if (service && SERVICE_CONCEPT[service]) {
conceptKey = SERVICE_CONCEPT[service]
conceptArgs = { detail: String(r.character_name || '') }
}
const metadata = r.metadata ? String(r.metadata) : null
const c = buildConcept(productName, service, String(r.character_name || ''), metadata)
movements.push({
date: new Date(r.timestamp),
conceptKey,
conceptArgs,
conceptRaw: productName,
conceptKey: c.conceptKey,
conceptArgs: c.conceptArgs,
conceptRaw: c.conceptRaw,
method: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
pd,
pd: purchasedPD(productName, service, metadata),
pv: null,
amount: Number(r.amount),
status: r.fulfilled ? 'delivered' : 'pending',
+24 -10
View File
@@ -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 []
}
+58
View File
@@ -0,0 +1,58 @@
// Concepto traducible de una transacción de home_stripelog, compartido por los
// historiales de PD/PV y de transacciones. Devuelve una CLAVE (+ argumentos) que
// la página traduce; `conceptRaw` es la reserva para pagos heredados sin servicio.
/** Slug de servicio (home_stripelog.service) -> clave de concepto (History.points.concept.*). */
export const SERVICE_CONCEPT: Record<string, string> = {
rename: 'rename',
customize: 'customize',
'change-race': 'changeRace',
'change-faction': 'changeFaction',
'level-up': 'levelUp',
gold: 'gold',
transfer: 'transfer',
'restore-item': 'restoreItem',
'send-gift': 'sendGift',
}
/** PD acreditados por un pago (si es una compra de PD), o null si es un servicio/ítem. */
export function purchasedPD(productName: string, service: string | null, metadata: string | null): number | null {
const m = /(\d+)\s*PD\b/i.exec(productName || '')
if (m) return Number(m[1])
if (service === 'dpoints') {
try {
const p = metadata ? JSON.parse(metadata).points : null
return p ? Number(p) : null
} catch {
return null
}
}
return null
}
export interface Concept {
conceptKey: string | null
conceptArgs: Record<string, string | number>
conceptRaw: string
}
/**
* Concepto de una fila de home_stripelog: compra de PD -> "{n} PD"; servicio
* conocido -> "{etiqueta}: {personaje}"; en otro caso, texto libre heredado.
*/
export function buildConcept(
productName: string,
service: string | null,
characterName: string,
metadata: string | null,
): Concept {
const raw = productName || '—'
const pd = purchasedPD(raw, service, metadata)
if (pd != null && (service === 'dpoints' || service === null)) {
return { conceptKey: 'pd', conceptArgs: { n: pd }, conceptRaw: raw }
}
if (service && SERVICE_CONCEPT[service]) {
return { conceptKey: SERVICE_CONCEPT[service], conceptArgs: { detail: characterName }, conceptRaw: raw }
}
return { conceptKey: null, conceptArgs: {}, conceptRaw: raw }
}