mirror of https://github.com/ghostfolio/ghostfolio
4 changed files with 58 additions and 50 deletions
@ -0,0 +1,34 @@ |
|||||
|
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; |
||||
|
import { Activity } from '@ghostfolio/common/interfaces'; |
||||
|
|
||||
|
import { AssetProfileToCreate } from './interfaces/interfaces'; |
||||
|
|
||||
|
/** |
||||
|
* Returns the asset profiles which at least one activity of the import uses. |
||||
|
* The asset profiles are created after the validation of the activities, |
||||
|
* thus an asset profile of an activity which is not imported must not be |
||||
|
* created. |
||||
|
*/ |
||||
|
export function getAssetProfilesToCreate({ |
||||
|
activities, |
||||
|
assetProfiles |
||||
|
}: { |
||||
|
activities: Partial<Activity>[]; |
||||
|
assetProfiles: AssetProfileToCreate[]; |
||||
|
}) { |
||||
|
const assetProfileIdentifiersToImport = new Set( |
||||
|
activities |
||||
|
.filter(({ error }) => { |
||||
|
return !error; |
||||
|
}) |
||||
|
.map(({ assetProfile }) => { |
||||
|
return getAssetProfileIdentifier(assetProfile); |
||||
|
}) |
||||
|
); |
||||
|
|
||||
|
return assetProfiles.filter(({ assetProfile }) => { |
||||
|
return assetProfileIdentifiersToImport.has( |
||||
|
getAssetProfileIdentifier(assetProfile) |
||||
|
); |
||||
|
}); |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
import { Prisma } from '@prisma/client'; |
||||
|
|
||||
|
export interface AssetProfileToCreate { |
||||
|
assetProfile: Prisma.SymbolProfileCreateInput; |
||||
|
marketDataObjects: Prisma.MarketDataUpdateInput[]; |
||||
|
} |
||||
Loading…
Reference in new issue