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 -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',