refactor: organize backend by business responsibility

This commit is contained in:
2026-09-13 13:52:57 +03:00
parent 7fde3ece6e
commit 8ba005346d
145 changed files with 3027 additions and 2346 deletions
@@ -0,0 +1,57 @@
import { TbankAccount } from './tbank.client';
const accountTypes = {
ACCOUNT_TYPE_TINKOFF: { type: 'BROKERAGE', name: 'Брокерский счет' },
ACCOUNT_TYPE_TINKOFF_IIS: {
type: 'INDIVIDUAL_INVESTMENT',
name: 'ИИС',
},
ACCOUNT_TYPE_INVEST_BOX: { type: 'INVEST_BOX', name: 'Инвесткопилка' },
ACCOUNT_TYPE_INVEST_FUND: {
type: 'MONEY_MARKET_FUND',
name: 'Фонд денежного рынка',
},
} as const;
type AccountType = keyof typeof accountTypes;
export type SupportedTbankAccount = {
id: string;
name: string;
type: (typeof accountTypes)[AccountType]['type'];
openedOn: string | null;
};
export function supportedTbankAccounts(
accounts: TbankAccount[],
): SupportedTbankAccount[] {
return accounts.flatMap((account) => {
const details = accountTypes[account.type as AccountType];
if (!details) return [];
return [
{
id: account.id,
name: account.name.trim() || details.name,
type: details.type,
openedOn: openedOn(account.openedDate?.seconds),
},
];
});
}
export function accessibleTbankAccount(
accounts: TbankAccount[],
accountId: string,
): TbankAccount | null {
return (
accounts.find(
(account) => account.id === accountId && account.type in accountTypes,
) ?? null
);
}
function openedOn(seconds: string | number | undefined): string | null {
if (seconds === undefined) return null;
const date = new Date(Number(seconds) * 1000);
if (Number.isNaN(date.valueOf())) return null;
return date.toISOString().slice(0, 10);
}