Files
vps-tracker/apps/api/src/services/fourvps/context.ts
T
DenozordecandCursor 87ab13e9f6
Docker / build (push) Has been cancelled
fix(accounts): учитывать baseCurrency хостера при отображении и синке баланса
API не всегда возвращает валюту (VDSina UserAPI); раньше подставлялся RUB вместо USD из настроек провайдера.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 02:18:40 +07:00

35 lines
1.4 KiB
TypeScript

import type { schema } from '@cfdm/db'
import { parseFourVpsCredentials } from '@cfdm/shared/utils/api-credentials'
type AccountRow = typeof schema.providerAccounts.$inferSelect
type ProviderRow = typeof schema.providers.$inferSelect
export interface FourvpsSyncAccount extends AccountRow {
apiType: '4vps'
apiBaseUrl: string
panelId: number | null
apiKey: string
providerBaseCurrency?: string | null
}
export function resolveFourvpsApi(
accountRow: AccountRow | null | undefined,
providerRow: ProviderRow | null | undefined,
): { apiType: string; apiBaseUrl: string } {
const apiType = String(providerRow?.apiType || accountRow?.apiType || '').trim()
const apiBaseUrl = String(providerRow?.apiBaseUrl || accountRow?.apiBaseUrl || '').trim()
return { apiType, apiBaseUrl }
}
export function fourvpsAccountRowForSync(
accountRow: AccountRow | null | undefined,
providerRow: ProviderRow | null | undefined,
): FourvpsSyncAccount | null {
if (!accountRow) return null
const { apiType, apiBaseUrl } = resolveFourvpsApi(accountRow, providerRow)
const cred = String(accountRow.apiCredentials || '').trim()
const { panelId, apiKey } = parseFourVpsCredentials(cred)
if (apiType !== '4vps' || !apiBaseUrl || !apiKey) return null
return { ...accountRow, apiType: '4vps', apiBaseUrl, panelId, apiKey, providerBaseCurrency: providerRow?.baseCurrency ?? null }
}