Browse Source

Refactoring

pull/4204/head
Thomas Kaul 7 months ago
parent
commit
565240d93a
  1. 62
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

62
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -20,8 +20,8 @@ import {
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client'; import { DataSource, SymbolProfile } from '@prisma/client';
import { isISIN } from 'class-validator';
import { format, isAfter, isBefore, isSameDay } from 'date-fns'; import { format, isAfter, isBefore, isSameDay } from 'date-fns';
import { uniqBy } from 'lodash';
@Injectable() @Injectable()
export class FinancialModelingPrepService implements DataProviderInterface { export class FinancialModelingPrepService implements DataProviderInterface {
@ -162,35 +162,49 @@ export class FinancialModelingPrepService implements DataProviderInterface {
let items: LookupItem[] = []; let items: LookupItem[] = [];
try { try {
const [resultSearch, resultSearchIsin] = await Promise.all([ if (isISIN(query)) {
fetch(`${this.URL}/search?query=${query}&apikey=${this.apiKey}`, { const result = await fetch(
signal: AbortSignal.timeout(
this.configurationService.get('REQUEST_TIMEOUT')
)
}).then((res) => res.json()),
fetch(
`${this.getUrl({ version: 4 })}/search/isin?isin=${query}&apikey=${this.apiKey}`, `${this.getUrl({ version: 4 })}/search/isin?isin=${query}&apikey=${this.apiKey}`,
{ {
signal: AbortSignal.timeout( signal: AbortSignal.timeout(
this.configurationService.get('REQUEST_TIMEOUT') this.configurationService.get('REQUEST_TIMEOUT')
) )
} }
).then((res) => res.json()) ).then((res) => res.json());
]);
items = result.map(({ companyName, currency, symbol }) => {
const result = uniqBy([...resultSearch, ...resultSearchIsin], 'symbol'); return {
currency,
items = result.map(({ companyName, currency, name, symbol }) => { symbol,
return { assetClass: undefined, // TODO
currency, assetSubClass: undefined, // TODO
symbol, dataProviderInfo: this.getDataProviderInfo(),
assetClass: undefined, // TODO dataSource: this.getName(),
assetSubClass: undefined, // TODO name: companyName
dataProviderInfo: this.getDataProviderInfo(), };
dataSource: this.getName(), });
name: name ?? companyName } else {
}; const result = await fetch(
}); `${this.URL}/search?query=${query}&apikey=${this.apiKey}`,
{
signal: AbortSignal.timeout(
this.configurationService.get('REQUEST_TIMEOUT')
)
}
).then((res) => res.json());
items = result.map(({ currency, name, symbol }) => {
return {
currency,
name,
symbol,
assetClass: undefined, // TODO
assetSubClass: undefined, // TODO
dataProviderInfo: this.getDataProviderInfo(),
dataSource: this.getName()
};
});
}
} catch (error) { } catch (error) {
let message = error; let message = error;

Loading…
Cancel
Save