Browse Source

Refactoring

pull/6981/head
Thomas Kaul 3 months ago
parent
commit
264193902b
  1. 39
      apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts

39
apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts

@ -18,25 +18,12 @@ export class AssetProfilesService {
{ dataSource, symbol }: AssetProfileIdentifier, { dataSource, symbol }: AssetProfileIdentifier,
assetProfileData: UpdateAssetProfileDataDto assetProfileData: UpdateAssetProfileDataDto
): Promise<EnhancedSymbolProfile> { ): Promise<EnhancedSymbolProfile> {
const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([ const notFoundMessage = `Could not find the asset profile for ${symbol} (${dataSource})`;
{
dataSource,
symbol
}
]);
if (!assetProfile) {
throw new NotFoundException(
`Could not find the asset profile for ${symbol} (${dataSource})`
);
}
const data = this.getAssetProfileDataUpdate(assetProfileData); const data = this.getAssetProfileDataUpdate(assetProfileData);
if (Object.keys(data).length === 0) { if (Object.keys(data).length > 0) {
return assetProfile; try {
}
await this.symbolProfileService.updateSymbolProfile( await this.symbolProfileService.updateSymbolProfile(
{ {
dataSource, dataSource,
@ -47,16 +34,30 @@ export class AssetProfilesService {
data data
) )
); );
} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2025'
) {
throw new NotFoundException(notFoundMessage);
}
throw error;
}
}
const [updatedAssetProfile] = const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([
await this.symbolProfileService.getSymbolProfiles([
{ {
dataSource, dataSource,
symbol symbol
} }
]); ]);
return updatedAssetProfile; if (!assetProfile) {
throw new NotFoundException(notFoundMessage);
}
return assetProfile;
} }
private getAssetProfileDataUpdate({ private getAssetProfileDataUpdate({

Loading…
Cancel
Save