diff --git a/apps/api/src/app/symbol/symbol.controller.ts b/apps/api/src/app/symbol/symbol.controller.ts index adea22187..d388d0829 100644 --- a/apps/api/src/app/symbol/symbol.controller.ts +++ b/apps/api/src/app/symbol/symbol.controller.ts @@ -29,10 +29,11 @@ export class SymbolController { @Get('lookup') @UseGuards(AuthGuard('jwt')) public async lookupSymbol( - @Query() { query } + @Query() { query = '' } ): Promise<{ items: LookupItem[] }> { try { - return this.symbolService.lookup(query); + const encodedQuery = encodeURIComponent(query.toLowerCase()); + return this.symbolService.lookup(encodedQuery); } catch { throw new HttpException( getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR), diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.ts index 3e487d60b..5740ea69f 100644 --- a/apps/api/src/app/symbol/symbol.service.ts +++ b/apps/api/src/app/symbol/symbol.service.ts @@ -25,11 +25,10 @@ export class SymbolService { }; } - public async lookup(aQuery = ''): Promise<{ items: LookupItem[] }> { - const query = aQuery.toLowerCase(); + public async lookup(aQuery: string): Promise<{ items: LookupItem[] }> { const results: { items: LookupItem[] } = { items: [] }; - if (!query) { + if (!aQuery) { return results; } @@ -40,7 +39,7 @@ export class SymbolService { // Add custom symbols const scraperConfigurations = await this.ghostfolioScraperApiService.getScraperConfigurations(); scraperConfigurations.forEach((scraperConfiguration) => { - if (scraperConfiguration.name.toLowerCase().startsWith(query)) { + if (scraperConfiguration.name.toLowerCase().startsWith(aQuery)) { results.items.push({ dataSource: DataSource.GHOSTFOLIO, name: scraperConfiguration.name, diff --git a/apps/api/src/services/data-provider.service.ts b/apps/api/src/services/data-provider.service.ts index e2d6af5f4..2183a514f 100644 --- a/apps/api/src/services/data-provider.service.ts +++ b/apps/api/src/services/data-provider.service.ts @@ -187,20 +187,17 @@ export class DataProviderService implements DataProviderInterface { } public async search(aSymbol: string) { - let results: { items: LookupItem[] } = { items: [] }; + return this.getDataProvider().search(aSymbol); + } + private getDataProvider() { switch (this.configurationService.get('DATA_SOURCES')[0]) { case DataSource.ALPHA_VANTAGE: - results = await this.alphaVantageService.search(aSymbol); - break; + return this.alphaVantageService; case DataSource.YAHOO: - results = await this.yahooFinanceService.search(aSymbol); - break; + return this.yahooFinanceService; default: - console.error('No data provider has been found.'); throw new Error('No data provider has been found.'); } - - return results; } } diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index f5dae437e..89ff79d33 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -4,7 +4,7 @@ export interface Environment extends CleanedEnvAccessors { ACCESS_TOKEN_SALT: string; ALPHA_VANTAGE_API_KEY: string; CACHE_TTL: number; - DATA_SOURCES: string[]; + DATA_SOURCES: string | string[]; // string is not correct, error in envalid? ENABLE_FEATURE_CUSTOM_SYMBOLS: boolean; ENABLE_FEATURE_FEAR_AND_GREED_INDEX: boolean; ENABLE_FEATURE_SOCIAL_LOGIN: boolean;