import { Injectable } from '@nestjs/common'; import type { CompanySettings } from '@basic-erp/sap-types'; import { SapClientService } from '../sap/sap-client.service.js'; /** Cuánto se recuerdan los ajustes de la empresa: cambian casi nunca. */ const TTL_MS = 10 * 60 * 1000; interface AdminInfo { RoundingMethod?: string; AccountSegmentsSeparator?: string | null; } /** * Ajustes de la empresa que necesita la interfaz. Se leen de `CompanyService_GetAdminInfo` y solo se entregan los * campos de `CompanySettings`: esa respuesta trae mucho más (cuentas bancarias, carpetas) que no debe salir. */ @Injectable() export class CompanyService { private cached: { at: number; value: CompanySettings } | null = null; constructor(private readonly sap: SapClientService) {} async settings(now = Date.now()): Promise { if (this.cached && now - this.cached.at < TTL_MS) return this.cached.value; const res = await this.sap.request({ method: 'POST', path: 'CompanyService_GetAdminInfo', body: {} }); const value: CompanySettings = { roundingEnabled: res.data?.RoundingMethod === 'tYES', accountSegmentsSeparator: res.data?.AccountSegmentsSeparator?.trim() || '-', }; this.cached = { at: now, value }; return value; } }