feat!: persist T-Bank data and synchronize reads
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Failing after 10m45s
Conventional commits / commits (pull_request) Successful in 29s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Failing after 10m37s
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Failing after 10m45s
Conventional commits / commits (pull_request) Successful in 29s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Failing after 10m37s
Store account membership, portfolio, operations, forecasts and market sources in SQLite. Coalesce scoped refreshes, fence connection revisions, preserve complete financial snapshots and stabilize operation period state. BREAKING CHANGE: investment reads return data/meta resource envelopes and locally persisted snapshots; consumers must use the matching OpenAPI contract and explicit synchronization endpoints.
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import type { InvestmentScreenDto } from './tbank-sync.dto';
|
||||
|
||||
// Reject fields from other screens before reserving any source work.
|
||||
export function normalizeScreen(
|
||||
input: InvestmentScreenDto,
|
||||
): InvestmentScreenDto {
|
||||
const commonPeriod = ['from', 'to'];
|
||||
const ledger = [...commonPeriod, 'categories', 'limit'];
|
||||
const allowed: Record<InvestmentScreenDto['screen'], string[]> = {
|
||||
accounts: [],
|
||||
account: ['accountId', ...ledger],
|
||||
operations: ['accountId', 'instrumentUid', ...ledger],
|
||||
income: ['accountId', ...commonPeriod],
|
||||
events: ['accountId', ...commonPeriod],
|
||||
stocks: ['query'],
|
||||
bonds: ['query'],
|
||||
stock: [
|
||||
'accountId',
|
||||
'instrumentUid',
|
||||
...ledger,
|
||||
'candlePeriod',
|
||||
'candleRange',
|
||||
],
|
||||
bond: [
|
||||
'accountId',
|
||||
'instrumentUid',
|
||||
...ledger,
|
||||
'candlePeriod',
|
||||
'candleRange',
|
||||
],
|
||||
};
|
||||
const fail = (): never => {
|
||||
throw new BadRequestException({
|
||||
message: [
|
||||
{
|
||||
property: 'scope',
|
||||
constraints: { scope: 'Invalid screen descriptor' },
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
if (!allowed[input.screen]) fail();
|
||||
for (const key of Object.keys(input))
|
||||
if (
|
||||
key !== 'screen' &&
|
||||
input[key as keyof InvestmentScreenDto] !== undefined &&
|
||||
!allowed[input.screen].includes(key)
|
||||
)
|
||||
fail();
|
||||
const accountId = input.accountId?.trim();
|
||||
const query = input.query?.trim().toUpperCase();
|
||||
if (
|
||||
['account', 'operations', 'income', 'events'].includes(input.screen) &&
|
||||
!accountId
|
||||
)
|
||||
fail();
|
||||
if (
|
||||
['stocks', 'bonds'].includes(input.screen) &&
|
||||
(!query || query.length < 2)
|
||||
)
|
||||
fail();
|
||||
if (['stock', 'bond'].includes(input.screen) && !input.instrumentUid) fail();
|
||||
if (input.accountId !== undefined && !accountId) fail();
|
||||
if (['income', 'events'].includes(input.screen)) {
|
||||
if (Boolean(input.from) !== Boolean(input.to)) fail();
|
||||
for (const value of [input.from, input.to])
|
||||
if (value && !/^\d{4}-\d{2}-\d{2}$/.test(value)) fail();
|
||||
}
|
||||
if (input.from && input.to && new Date(input.from) > new Date(input.to))
|
||||
fail();
|
||||
if (
|
||||
input.candleRange &&
|
||||
new Date(input.candleRange.from) >= new Date(input.candleRange.to)
|
||||
)
|
||||
fail();
|
||||
// Fixed field order is part of coalescing, irrespective of JSON input order.
|
||||
return {
|
||||
screen: input.screen,
|
||||
...(accountId ? { accountId } : {}),
|
||||
...(input.from ? { from: input.from } : {}),
|
||||
...(input.to ? { to: input.to } : {}),
|
||||
...(input.instrumentUid
|
||||
? { instrumentUid: input.instrumentUid.toLowerCase() }
|
||||
: {}),
|
||||
...(query ? { query } : {}),
|
||||
...(input.candlePeriod ? { candlePeriod: input.candlePeriod } : {}),
|
||||
...(input.candleRange
|
||||
? {
|
||||
candleRange: {
|
||||
from: new Date(input.candleRange.from).toISOString(),
|
||||
to: new Date(input.candleRange.to).toISOString(),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(input.categories
|
||||
? { categories: [...new Set(input.categories)].sort() }
|
||||
: {}),
|
||||
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user