Browse Source

Refactoring

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

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

@ -18,45 +18,46 @@ export class AssetProfilesService {
{ dataSource, symbol }: AssetProfileIdentifier,
assetProfileData: UpdateAssetProfileDataDto
): Promise<EnhancedSymbolProfile> {
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({

Loading…
Cancel
Save