|
|
@ -536,7 +536,6 @@ export class ImportService { |
|
|
|
|
|
|
|
|
const assetProfilesToCreate: { |
|
|
const assetProfilesToCreate: { |
|
|
assetProfile: Prisma.SymbolProfileCreateInput; |
|
|
assetProfile: Prisma.SymbolProfileCreateInput; |
|
|
assetProfileIdentifier: string; |
|
|
|
|
|
marketDataObjects: Prisma.MarketDataUpdateInput[]; |
|
|
marketDataObjects: Prisma.MarketDataUpdateInput[]; |
|
|
}[] = []; |
|
|
}[] = []; |
|
|
|
|
|
|
|
|
@ -644,11 +643,7 @@ export class ImportService { |
|
|
// is known which activities are imported
|
|
|
// is known which activities are imported
|
|
|
assetProfilesToCreate.push({ |
|
|
assetProfilesToCreate.push({ |
|
|
marketDataObjects, |
|
|
marketDataObjects, |
|
|
assetProfile: assetProfileToCreate, |
|
|
assetProfile: assetProfileToCreate |
|
|
assetProfileIdentifier: getAssetProfileIdentifier({ |
|
|
|
|
|
symbol, |
|
|
|
|
|
dataSource: assetProfileWithMarketData.dataSource |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
// Insert or update market data
|
|
|
// Insert or update market data
|
|
|
@ -738,35 +733,21 @@ export class ImportService { |
|
|
return id === TAG_ID_DRAFT; |
|
|
return id === TAG_ID_DRAFT; |
|
|
}) ?? { id: TAG_ID_DRAFT, name: 'DRAFT' }; |
|
|
}) ?? { id: TAG_ID_DRAFT, name: 'DRAFT' }; |
|
|
|
|
|
|
|
|
if (assetProfilesToCreate.length) { |
|
|
// Create the new asset profiles of the activities to import only, so that
|
|
|
// Create the new asset profiles of the activities to import only, so
|
|
|
// no unused asset profile remains, for example if an activity is a
|
|
|
// that no unused asset profile remains, for example if an activity is a
|
|
|
// duplicate. An asset profile which is created before the validation of
|
|
|
// duplicate. An asset profile which is created before the validation of
|
|
|
// the activities would stay behind, because the import is not rolled back
|
|
|
// the activities would stay behind, because the import is not rolled
|
|
|
// on an error.
|
|
|
// back on an error.
|
|
|
for (const { |
|
|
const assetProfileIdentifiersToImport = new Set( |
|
|
assetProfile, |
|
|
activitiesExtendedWithErrors |
|
|
marketDataObjects |
|
|
.filter(({ error }) => { |
|
|
} of this.getAssetProfilesToCreate({ |
|
|
return !error; |
|
|
activities: activitiesExtendedWithErrors, |
|
|
}) |
|
|
assetProfiles: assetProfilesToCreate |
|
|
.map(({ assetProfile }) => { |
|
|
})) { |
|
|
return getAssetProfileIdentifier(assetProfile); |
|
|
await this.symbolProfileService.add(assetProfile); |
|
|
}) |
|
|
|
|
|
); |
|
|
await this.marketDataService.updateMany({ data: marketDataObjects }); |
|
|
|
|
|
|
|
|
for (const { |
|
|
|
|
|
assetProfile, |
|
|
|
|
|
assetProfileIdentifier, |
|
|
|
|
|
marketDataObjects |
|
|
|
|
|
} of assetProfilesToCreate) { |
|
|
|
|
|
if (!assetProfileIdentifiersToImport.has(assetProfileIdentifier)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.symbolProfileService.add(assetProfile); |
|
|
|
|
|
|
|
|
|
|
|
await this.marketDataService.updateMany({ data: marketDataObjects }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const activities: Activity[] = []; |
|
|
const activities: Activity[] = []; |
|
|
@ -1105,6 +1086,39 @@ export class ImportService { |
|
|
return matchingAccountsOfUser[0]; |
|
|
return matchingAccountsOfUser[0]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 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. |
|
|
|
|
|
*/ |
|
|
|
|
|
private getAssetProfilesToCreate({ |
|
|
|
|
|
activities, |
|
|
|
|
|
assetProfiles |
|
|
|
|
|
}: { |
|
|
|
|
|
activities: Partial<Activity>[]; |
|
|
|
|
|
assetProfiles: { |
|
|
|
|
|
assetProfile: Prisma.SymbolProfileCreateInput; |
|
|
|
|
|
marketDataObjects: Prisma.MarketDataUpdateInput[]; |
|
|
|
|
|
}[]; |
|
|
|
|
|
}) { |
|
|
|
|
|
const assetProfileIdentifiersToImport = new Set( |
|
|
|
|
|
activities |
|
|
|
|
|
.filter(({ error }) => { |
|
|
|
|
|
return !error; |
|
|
|
|
|
}) |
|
|
|
|
|
.map(({ assetProfile }) => { |
|
|
|
|
|
return getAssetProfileIdentifier(assetProfile); |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return assetProfiles.filter(({ assetProfile }) => { |
|
|
|
|
|
return assetProfileIdentifiersToImport.has( |
|
|
|
|
|
getAssetProfileIdentifier(assetProfile) |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private isUniqueAccount(accounts: AccountWithValue[]) { |
|
|
private isUniqueAccount(accounts: AccountWithValue[]) { |
|
|
const uniqueAccountIds = new Set<string>(); |
|
|
const uniqueAccountIds = new Set<string>(); |
|
|
|
|
|
|
|
|
|