import type { RowDataPacket } from 'mysql2' import { db, DB } from './db' // Servicios con precio Ășnico (una fila) -> tabla django_wow. export const PRICE_TABLES: Record = { rename: 'home_renameprice', customize: 'home_customizeprice', 'change-race': 'home_changeraceprice', 'change-faction': 'home_changefactionprice', 'level-up': 'home_levelupprice', transfer: 'home_transferprice', } export interface PriceRow { service: string price: number } export async function getAllPrices(): Promise { const out: PriceRow[] = [] for (const [service, table] of Object.entries(PRICE_TABLES)) { let price = 0 try { const [rows] = await db(DB.default).query(`SELECT price FROM ${table} LIMIT 1`) price = rows[0] ? Number(rows[0].price) : 0 } catch { /* ignore */ } out.push({ service, price }) } return out } /** Fija el precio (fila Ășnica) de un servicio. */ export async function setPrice(service: string, value: number): Promise { const table = PRICE_TABLES[service] if (!table || !(value >= 0)) return false await db(DB.default).query(`DELETE FROM ${table}`) await db(DB.default).query(`INSERT INTO ${table} (price) VALUES (?)`, [value]) return true }