diff --git a/CHANGELOG.md b/CHANGELOG.md index 696e26d62..bd21f635a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Improved the search for asset profiles with `MANUAL` data source in the create or update activity dialog - Improved the usability of the link to manage access with a new icon - Improved support to import activities by `isin` in the _Yahoo Finance_ service - Improved the language localization for Polish (`pl`) diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts index 3faf5b583..7c0df7a9f 100644 --- a/apps/api/src/services/data-provider/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -618,7 +618,8 @@ export class DataProviderService { promises.push( dataProviderService.search({ includeIndices, - query + query, + userId: user.id }) ); } diff --git a/apps/api/src/services/data-provider/interfaces/data-provider.interface.ts b/apps/api/src/services/data-provider/interfaces/data-provider.interface.ts index e448b4e15..5c316aac2 100644 --- a/apps/api/src/services/data-provider/interfaces/data-provider.interface.ts +++ b/apps/api/src/services/data-provider/interfaces/data-provider.interface.ts @@ -79,4 +79,5 @@ export interface GetQuotesParams { export interface GetSearchParams { includeIndices?: boolean; query: string; + userId?: string; } diff --git a/apps/api/src/services/data-provider/manual/manual.service.ts b/apps/api/src/services/data-provider/manual/manual.service.ts index c3e274005..6f1c56f15 100644 --- a/apps/api/src/services/data-provider/manual/manual.service.ts +++ b/apps/api/src/services/data-provider/manual/manual.service.ts @@ -26,7 +26,6 @@ import { import { Injectable, Logger } from '@nestjs/common'; import { DataSource, SymbolProfile } from '@prisma/client'; import * as cheerio from 'cheerio'; -import { isUUID } from 'class-validator'; import { addDays, format, isBefore } from 'date-fns'; import got, { Headers } from 'got'; import * as jsonpath from 'jsonpath'; @@ -219,41 +218,48 @@ export class ManualService implements DataProviderInterface { return undefined; } - public async search({ query }: GetSearchParams): Promise { - let items = await this.prismaService.symbolProfile.findMany({ + public async search({ + query, + userId + }: GetSearchParams): Promise { + const items = await this.prismaService.symbolProfile.findMany({ select: { assetClass: true, assetSubClass: true, currency: true, dataSource: true, name: true, - symbol: true + symbol: true, + userId: true }, where: { - OR: [ + AND: [ { - dataSource: this.getName(), - name: { - mode: 'insensitive', - startsWith: query - } + dataSource: this.getName() }, { - dataSource: this.getName(), - symbol: { - mode: 'insensitive', - startsWith: query - } + OR: [ + { + name: { + mode: 'insensitive', + startsWith: query + } + }, + { + symbol: { + mode: 'insensitive', + startsWith: query + } + } + ] + }, + { + OR: [{ userId }, { userId: null }] } ] } }); - items = items.filter(({ symbol }) => { - // Remove UUID symbols (activities of type ITEM) - return !isUUID(symbol); - }); - return { items: items.map((item) => { return { ...item, dataProviderInfo: this.getDataProviderInfo() }; diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts index cb21c255d..feeb4abc8 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts @@ -20,7 +20,6 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { AssetClass, AssetSubClass, Tag, Type } from '@prisma/client'; -import { isUUID } from 'class-validator'; import { isAfter, isToday } from 'date-fns'; import { EMPTY, Observable, Subject, lastValueFrom, of } from 'rxjs'; import { catchError, delay, map, startWith, takeUntil } from 'rxjs/operators'; @@ -476,10 +475,8 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { fee: this.activityForm.get('fee').value, quantity: this.activityForm.get('quantity').value, symbol: - this.activityForm.get('searchSymbol').value?.symbol === undefined || - isUUID(this.activityForm.get('searchSymbol').value?.symbol) - ? this.activityForm.get('name').value - : this.activityForm.get('searchSymbol').value.symbol, + this.activityForm.get('searchSymbol')?.value?.symbol ?? + this.activityForm.get('name')?.value, tags: this.activityForm.get('tags').value, type: this.activityForm.get('type').value, unitPrice: this.activityForm.get('unitPrice').value