mirror of https://github.com/ghostfolio/ghostfolio
8 changed files with 82 additions and 3 deletions
@ -0,0 +1,44 @@ |
|||
import { DataEnhancerInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-enhancer.interface'; |
|||
import { HttpException, Inject, Injectable } from '@nestjs/common'; |
|||
import { Prisma } from '@prisma/client'; |
|||
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|||
|
|||
@Injectable() |
|||
export class DataEnhancerService { |
|||
public constructor( |
|||
@Inject('DataEnhancers') |
|||
private readonly dataEnhancers: DataEnhancerInterface[] |
|||
) {} |
|||
|
|||
public async enhance(aName: string) { |
|||
const dataEnhancer = this.dataEnhancers.find((dataEnhancer) => { |
|||
return dataEnhancer.getName() === aName; |
|||
}); |
|||
|
|||
if (!dataEnhancer) { |
|||
throw new HttpException( |
|||
getReasonPhrase(StatusCodes.NOT_FOUND), |
|||
StatusCodes.NOT_FOUND |
|||
); |
|||
} |
|||
|
|||
try { |
|||
const assetProfile = await dataEnhancer.enhance({ |
|||
response: { |
|||
assetClass: 'EQUITY', |
|||
assetSubClass: 'ETF' |
|||
}, |
|||
symbol: dataEnhancer.getTestSymbol() |
|||
}); |
|||
|
|||
if ( |
|||
(assetProfile.countries as unknown as Prisma.JsonArray)?.length > 0 && |
|||
(assetProfile.sectors as unknown as Prisma.JsonArray)?.length > 0 |
|||
) { |
|||
return true; |
|||
} |
|||
} catch {} |
|||
|
|||
return false; |
|||
} |
|||
} |
Loading…
Reference in new issue