From 264193902be9f417a719a717e0bfeb5760772f4d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 11 Jun 2026 22:02:55 +0200 Subject: [PATCH] Refactoring --- .../asset-profiles/asset-profiles.service.ts | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts b/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts index 9fa3ec47c..ef24372af 100644 --- a/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts +++ b/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts @@ -18,45 +18,46 @@ export class AssetProfilesService { { dataSource, symbol }: AssetProfileIdentifier, assetProfileData: UpdateAssetProfileDataDto ): Promise { - const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([ - { - dataSource, - symbol - } - ]); - - if (!assetProfile) { - throw new NotFoundException( - `Could not find the asset profile for ${symbol} (${dataSource})` - ); - } + const notFoundMessage = `Could not find the asset profile for ${symbol} (${dataSource})`; const data = this.getAssetProfileDataUpdate(assetProfileData); - if (Object.keys(data).length === 0) { - return assetProfile; + if (Object.keys(data).length > 0) { + try { + await this.symbolProfileService.updateSymbolProfile( + { + dataSource, + symbol + }, + this.symbolProfileService.getAssetProfileUpdateInput( + { dataSource, symbol }, + data + ) + ); + } catch (error) { + if ( + error instanceof Prisma.PrismaClientKnownRequestError && + error.code === 'P2025' + ) { + throw new NotFoundException(notFoundMessage); + } + + throw error; + } } - await this.symbolProfileService.updateSymbolProfile( + const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([ { dataSource, symbol - }, - this.symbolProfileService.getAssetProfileUpdateInput( - { dataSource, symbol }, - data - ) - ); + } + ]); - const [updatedAssetProfile] = - await this.symbolProfileService.getSymbolProfiles([ - { - dataSource, - symbol - } - ]); + if (!assetProfile) { + throw new NotFoundException(notFoundMessage); + } - return updatedAssetProfile; + return assetProfile; } private getAssetProfileDataUpdate({