mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
998 B
34 lines
998 B
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)
|
|
);
|
|
});
|
|
}
|
|
|