Use owner enums for error and T-Bank protocol values with ESLint regression checks. Preserve open wire fallbacks and keep protocol imports independent of DI and Prisma. Verified npm ci, verify, 226 unit tests, 262 isolated e2e tests and unchanged OpenAPI.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import type { TbankShare } from '../../../../integrations/tbank/tbank.api';
|
|
|
|
import { TbankInstrumentType } from '../../../../integrations/tbank/tbank-protocol';
|
|
|
|
export const catalogSearchLimit = 30;
|
|
|
|
export function selectCatalogInstruments<T extends TbankShare>(
|
|
found: T[],
|
|
query: string,
|
|
instrumentType: 'bond' | 'share',
|
|
): (T & { uid: string })[] {
|
|
const seen = new Set<string>();
|
|
const kind =
|
|
instrumentType === 'share'
|
|
? TbankInstrumentType.Share
|
|
: TbankInstrumentType.Bond;
|
|
const preferredClass = instrumentType === 'share' ? 'TQBR' : 'TQOB';
|
|
return found
|
|
.filter(
|
|
(instrument): instrument is T & { uid: string } =>
|
|
Boolean(instrument.uid?.trim()) && instrument.instrumentKind === kind,
|
|
)
|
|
.sort(
|
|
(a, b) =>
|
|
Number(b.apiTradeAvailableFlag === true) -
|
|
Number(a.apiTradeAvailableFlag === true) ||
|
|
Number(b.ticker?.toUpperCase() === query.toUpperCase()) -
|
|
Number(a.ticker?.toUpperCase() === query.toUpperCase()) ||
|
|
Number(b.classCode === preferredClass) -
|
|
Number(a.classCode === preferredClass) ||
|
|
a.uid.localeCompare(b.uid),
|
|
)
|
|
.filter((instrument) => {
|
|
const key = instrument.isin?.trim()
|
|
? `isin:${instrument.isin.trim().toUpperCase()}`
|
|
: `uid:${instrument.uid}`;
|
|
if (seen.has(key)) return false;
|
|
seen.add(key);
|
|
return true;
|
|
});
|
|
}
|