From 309179c45048a7689af9e39f5f520419da9d2648 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 30 Oct 2026 09:56:45 +0100 Subject: [PATCH] Fix validation of update activity endpoint --- .../activities/activities.controller.ts | 99 +++++++++++++------ 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/apps/api/src/app/endpoints/activities/activities.controller.ts b/apps/api/src/app/endpoints/activities/activities.controller.ts index 6ac820874e..2f38ca5739 100644 --- a/apps/api/src/app/endpoints/activities/activities.controller.ts +++ b/apps/api/src/app/endpoints/activities/activities.controller.ts @@ -241,36 +241,12 @@ export class ActivitiesController { userSubscription }: ImpersonationContext ): Promise { - // Evaluate the more restrictive subscription of the authenticated user - // and the owner of the activity - const subscription = - userSubscription?.type === SubscriptionType.Basic - ? userSubscription - : authenticatedUserSubscription; - - try { - await this.dataProviderService.validateActivities({ - subscription, - userId, - activitiesDto: [ - { - currency: data.currency, - dataSource: data.dataSource, - symbol: data.symbol, - type: data.type - } - ], - maxActivitiesToImport: 1 - }); - } catch (error) { - throw new HttpException( - { - error: getReasonPhrase(StatusCodes.BAD_REQUEST), - message: [error.message] - }, - StatusCodes.BAD_REQUEST - ); - } + await this.validateActivity({ + authenticatedUserSubscription, + userId, + userSubscription, + activityDto: data + }); const currency = data.currency; const customCurrency = data.customCurrency; @@ -344,7 +320,12 @@ export class ActivitiesController { @UseInterceptors(TransformDataSourceInRequestInterceptor) public async updateActivity( @Body() data: UpdateOrderDto, - @Impersonation() { userId }: ImpersonationContext, + @Impersonation() + { + authenticatedUserSubscription, + userId, + userSubscription + }: ImpersonationContext, @Param('id') id: string ): Promise { const originalActivity = await this.activitiesService.order({ @@ -359,6 +340,23 @@ export class ActivitiesController { ); } + const [originalAssetProfile] = + await this.symbolProfileService.getSymbolProfilesByIds([ + originalActivity.symbolProfileId + ]); + + if ( + originalAssetProfile.dataSource !== data.dataSource || + originalAssetProfile.symbol !== data.symbol + ) { + await this.validateActivity({ + authenticatedUserSubscription, + userId, + userSubscription, + activityDto: data + }); + } + const date = parseISO(data.date); const accountId = data.accountId; @@ -428,4 +426,43 @@ export class ActivitiesController { 'userId' ]); } + + private async validateActivity({ + activityDto: { currency, dataSource, symbol, type }, + authenticatedUserSubscription, + userId, + userSubscription + }: Pick< + ImpersonationContext, + 'authenticatedUserSubscription' | 'userId' | 'userSubscription' + > & { + activityDto: Pick< + CreateOrderDto, + 'currency' | 'dataSource' | 'symbol' | 'type' + >; + }) { + // Evaluate the more restrictive subscription of the authenticated user + // and the owner of the activity + const subscription = + userSubscription?.type === SubscriptionType.Basic + ? userSubscription + : authenticatedUserSubscription; + + try { + await this.dataProviderService.validateActivities({ + subscription, + userId, + activitiesDto: [{ currency, dataSource, symbol, type }], + maxActivitiesToImport: 1 + }); + } catch (error) { + throw new HttpException( + { + error: getReasonPhrase(StatusCodes.BAD_REQUEST), + message: [error.message] + }, + StatusCodes.BAD_REQUEST + ); + } + } }