|
@ -42,7 +42,7 @@ export class ImportService { |
|
|
return Account; |
|
|
return Account; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const mostFrequentAccount = this.getMostFrequentAccount(accounts); |
|
|
const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined; |
|
|
|
|
|
|
|
|
const [[assetProfile], dividends] = await Promise.all([ |
|
|
const [[assetProfile], dividends] = await Promise.all([ |
|
|
this.symbolProfileService.getSymbolProfiles([ |
|
|
this.symbolProfileService.getSymbolProfiles([ |
|
@ -71,11 +71,11 @@ export class ImportService { |
|
|
const value = new Big(quantity).mul(marketPrice).toNumber(); |
|
|
const value = new Big(quantity).mul(marketPrice).toNumber(); |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
|
|
|
Account, |
|
|
quantity, |
|
|
quantity, |
|
|
value, |
|
|
value, |
|
|
Account: mostFrequentAccount, |
|
|
accountId: Account?.id, |
|
|
accountId: mostFrequentAccount.id, |
|
|
accountUserId: undefined, |
|
|
accountUserId: mostFrequentAccount.userId, |
|
|
|
|
|
comment: undefined, |
|
|
comment: undefined, |
|
|
createdAt: undefined, |
|
|
createdAt: undefined, |
|
|
date: parseDate(dateString), |
|
|
date: parseDate(dateString), |
|
@ -88,7 +88,7 @@ export class ImportService { |
|
|
type: 'DIVIDEND', |
|
|
type: 'DIVIDEND', |
|
|
unitPrice: marketPrice, |
|
|
unitPrice: marketPrice, |
|
|
updatedAt: undefined, |
|
|
updatedAt: undefined, |
|
|
userId: mostFrequentAccount.userId, |
|
|
userId: Account?.userId, |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( |
|
|
value, |
|
|
value, |
|
|
assetProfile.currency, |
|
|
assetProfile.currency, |
|
@ -244,29 +244,14 @@ export class ImportService { |
|
|
return activities; |
|
|
return activities; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getMostFrequentAccount(accounts: AccountWithPlatform[]) { |
|
|
private isUniqueAccount(accounts: AccountWithPlatform[]) { |
|
|
const accountFrequencyCountMap: { [accountId: string]: number } = {}; |
|
|
const uniqueAccountIds = new Set<string>(); |
|
|
|
|
|
|
|
|
// Iterate through the array of accounts and increment the frequency for each account
|
|
|
|
|
|
for (const account of accounts) { |
|
|
for (const account of accounts) { |
|
|
accountFrequencyCountMap[account.id] = |
|
|
uniqueAccountIds.add(account.id); |
|
|
(accountFrequencyCountMap[account.id] || 0) + 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Find the account with the highest frequency
|
|
|
|
|
|
let maxFrequencyCount = 0; |
|
|
|
|
|
let mostFrequentAccount: AccountWithPlatform; |
|
|
|
|
|
|
|
|
|
|
|
for (const accountId in accountFrequencyCountMap) { |
|
|
|
|
|
if (accountFrequencyCountMap[accountId] > maxFrequencyCount) { |
|
|
|
|
|
mostFrequentAccount = accounts.find( |
|
|
|
|
|
(account) => account.id === accountId |
|
|
|
|
|
); |
|
|
|
|
|
maxFrequencyCount = accountFrequencyCountMap[accountId]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return mostFrequentAccount; |
|
|
return uniqueAccountIds.size === 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async validateActivities({ |
|
|
private async validateActivities({ |
|
|