diff --git a/apps/api/src/app/endpoints/public/public.controller.ts b/apps/api/src/app/endpoints/public/public.controller.ts index 633e6418a..6e025936d 100644 --- a/apps/api/src/app/endpoints/public/public.controller.ts +++ b/apps/api/src/app/endpoints/public/public.controller.ts @@ -69,8 +69,7 @@ export class PublicController { hasDetails = user.subscription.type === SubscriptionType.Premium; } - const { filters: portfolioFilters = [] } = (access.settings ?? - {}) as AccessSettings; + const { filters } = (access.settings ?? {}) as AccessSettings; const [ { createdAt, holdings, markets }, @@ -79,7 +78,7 @@ export class PublicController { { performance: performanceYtd } ] = await Promise.all([ this.portfolioService.getDetails({ - filters: portfolioFilters.length > 0 ? portfolioFilters : undefined, + filters, impersonationId: access.userId, userId: user.id, withMarkets: true @@ -87,7 +86,7 @@ export class PublicController { ...['1d', 'max', 'ytd'].map((dateRange) => { return this.portfolioService.getPerformance({ dateRange, - filters: portfolioFilters.length > 0 ? portfolioFilters : undefined, + filters, impersonationId: undefined, userId: user.id }); @@ -95,7 +94,7 @@ export class PublicController { ]); const { activities } = await this.activitiesService.getActivities({ - filters: portfolioFilters.length > 0 ? portfolioFilters : undefined, + filters, sortColumn: 'date', sortDirection: 'desc', take: 10, diff --git a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts index 3db40781e..77699a304 100644 --- a/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts +++ b/apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts @@ -259,58 +259,6 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { }); } - private updateFiltersFormControl(existingFilters: Filter[] | undefined) { - if (!existingFilters?.length) { - return; - } - - const filterValue: Partial = {}; - - const accountFilter = existingFilters.find(({ type }) => { - return type === 'ACCOUNT'; - }); - if (accountFilter && this.accounts.length > 0) { - filterValue.account = accountFilter.id; - } - - const assetClassFilter = existingFilters.find(({ type }) => { - return type === 'ASSET_CLASS'; - }); - if (assetClassFilter && this.assetClasses.length > 0) { - filterValue.assetClass = assetClassFilter.id; - } - - const dataSourceFilter = existingFilters.find(({ type }) => { - return type === 'DATA_SOURCE'; - }); - const symbolFilter = existingFilters.find(({ type }) => { - return type === 'SYMBOL'; - }); - if (dataSourceFilter && symbolFilter && this.holdings.length > 0) { - const holding = this.holdings.find(({ assetProfile }) => { - return ( - assetProfile.dataSource === dataSourceFilter.id && - assetProfile.symbol === symbolFilter.id - ); - }); - if (holding) { - filterValue.holding = holding; - } - } - - const tagFilter = existingFilters.find(({ type }) => { - return type === 'TAG'; - }); - if (tagFilter && this.tags.length > 0) { - filterValue.tag = tagFilter.id; - } - - if (Object.keys(filterValue).length > 0) { - this.accessForm.get('filters')?.setValue(filterValue); - this.changeDetectorRef.markForCheck(); - } - } - private async createAccess() { const filters = this.buildFilters(); @@ -395,4 +343,62 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit { console.error(error); } } + + private updateFiltersFormControl(existingFilters: Filter[] | undefined) { + if (!existingFilters?.length) { + return; + } + + const filterValue: Partial = {}; + + const accountFilter = existingFilters.find(({ type }) => { + return type === 'ACCOUNT'; + }); + + if (accountFilter && this.accounts.length > 0) { + filterValue.account = accountFilter.id; + } + + const assetClassFilter = existingFilters.find(({ type }) => { + return type === 'ASSET_CLASS'; + }); + + if (assetClassFilter && this.assetClasses.length > 0) { + filterValue.assetClass = assetClassFilter.id; + } + + const dataSourceFilter = existingFilters.find(({ type }) => { + return type === 'DATA_SOURCE'; + }); + + const symbolFilter = existingFilters.find(({ type }) => { + return type === 'SYMBOL'; + }); + + if (dataSourceFilter && symbolFilter && this.holdings.length > 0) { + const holding = this.holdings.find(({ assetProfile }) => { + return ( + assetProfile.dataSource === dataSourceFilter.id && + assetProfile.symbol === symbolFilter.id + ); + }); + + if (holding) { + filterValue.holding = holding; + } + } + + const tagFilter = existingFilters.find(({ type }) => { + return type === 'TAG'; + }); + + if (tagFilter && this.tags.length > 0) { + filterValue.tag = tagFilter.id; + } + + if (Object.keys(filterValue).length > 0) { + this.accessForm.get('filters')?.setValue(filterValue); + this.changeDetectorRef.markForCheck(); + } + } } diff --git a/apps/client/src/app/components/user-account-access/user-account-access.component.ts b/apps/client/src/app/components/user-account-access/user-account-access.component.ts index b20bc70d9..c9d74b6b1 100644 --- a/apps/client/src/app/components/user-account-access/user-account-access.component.ts +++ b/apps/client/src/app/components/user-account-access/user-account-access.component.ts @@ -128,7 +128,7 @@ export class GfUserAccountAccessComponent implements OnInit { if (params['createDialog']) { this.openCreateAccessDialog(); } else if (params['editDialog'] && params['accessId']) { - this.openUpdateAccessDialog(params['accessId'] as string); + this.openUpdateAccessDialog(params['accessId']); } }); diff --git a/libs/common/src/lib/interfaces/access-settings.interface.ts b/libs/common/src/lib/interfaces/access-settings.interface.ts new file mode 100644 index 000000000..5c240089f --- /dev/null +++ b/libs/common/src/lib/interfaces/access-settings.interface.ts @@ -0,0 +1,5 @@ +import { Filter } from './filter.interface'; + +export interface AccessSettings { + filters?: Filter[]; +} diff --git a/libs/common/src/lib/interfaces/access.interface.ts b/libs/common/src/lib/interfaces/access.interface.ts index ff1c1ccc8..f3e74e756 100644 --- a/libs/common/src/lib/interfaces/access.interface.ts +++ b/libs/common/src/lib/interfaces/access.interface.ts @@ -2,11 +2,7 @@ import { AccessType } from '@ghostfolio/common/types'; import { AccessPermission } from '@prisma/client'; -import { Filter } from './filter.interface'; - -export interface AccessSettings { - filters?: Filter[]; -} +import { AccessSettings } from './access-settings.interface'; export interface Access { alias?: string; diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index 2ea6631d5..393810edd 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/libs/common/src/lib/interfaces/index.ts @@ -1,4 +1,5 @@ -import type { Access, AccessSettings } from './access.interface'; +import type { AccessSettings } from './access-settings.interface'; +import type { Access } from './access.interface'; import type { AccountBalance } from './account-balance.interface'; import type { Activity, ActivityError } from './activities.interface'; import type { AdminData } from './admin-data.interface';