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,
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,
@ -47,16 +34,30 @@ export class AssetProfilesService {
data
)
);
} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2025'
) {
throw new NotFoundException(notFoundMessage);
}
throw error;
}
}
const [updatedAssetProfile] =
await this.symbolProfileService.getSymbolProfiles([
const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([
{
dataSource,
symbol
}
]);
return updatedAssetProfile;
if (!assetProfile) {
throw new NotFoundException(notFoundMessage);
}
return assetProfile;
}
private getAssetProfileDataUpdate({

Loading…
Cancel
Save