| 
						
						
							
								
							
						
						
					 | 
					@ -74,8 +74,25 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        const value = new Big(quantity).mul(marketPrice).toNumber(); | 
					 | 
					 | 
					        const value = new Big(quantity).mul(marketPrice).toNumber(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        const isDuplicate = orders.some((activity) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					          return ( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.SymbolProfile.currency === assetProfile.currency && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.SymbolProfile.dataSource === assetProfile.dataSource && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            isSameDay(activity.date, parseDate(dateString)) && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.quantity === quantity && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.SymbolProfile.symbol === assetProfile.symbol && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.type === 'DIVIDEND' && | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            activity.unitPrice === marketPrice | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					          ); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        const error: ActivityError = isDuplicate | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					          ? { code: 'IS_DUPLICATE' } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					          : undefined; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        return { | 
					 | 
					 | 
					        return { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          Account, | 
					 | 
					 | 
					          Account, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					          error, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          quantity, | 
					 | 
					 | 
					          quantity, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          value, | 
					 | 
					 | 
					          value, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          accountId: Account?.id, | 
					 | 
					 | 
					          accountId: Account?.id, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -83,7 +100,6 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          comment: undefined, | 
					 | 
					 | 
					          comment: undefined, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          createdAt: undefined, | 
					 | 
					 | 
					          createdAt: undefined, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          date: parseDate(dateString), | 
					 | 
					 | 
					          date: parseDate(dateString), | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          // TODO: Add evaluated error state
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          fee: 0, | 
					 | 
					 | 
					          fee: 0, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          feeInBaseCurrency: 0, | 
					 | 
					 | 
					          feeInBaseCurrency: 0, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					          id: assetProfile.id, | 
					 | 
					 | 
					          id: assetProfile.id, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -208,7 +224,7 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      userId | 
					 | 
					 | 
					      userId | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    }); | 
					 | 
					 | 
					    }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    const activitiesMarkedAsDuplicates = await this.markActivitiesAsDuplicates({ | 
					 | 
					 | 
					    const activitiesExtendedWithErrors = await this.extendActivitiesWithErrors({ | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					      activitiesDto, | 
					 | 
					 | 
					      activitiesDto, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      userId | 
					 | 
					 | 
					      userId | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    }); | 
					 | 
					 | 
					    }); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -237,7 +253,7 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      SymbolProfile: assetProfile, | 
					 | 
					 | 
					      SymbolProfile: assetProfile, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      type, | 
					 | 
					 | 
					      type, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      unitPrice | 
					 | 
					 | 
					      unitPrice | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    } of activitiesMarkedAsDuplicates) { | 
					 | 
					 | 
					    } of activitiesExtendedWithErrors) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					      const validatedAccount = accounts.find(({ id }) => { | 
					 | 
					 | 
					      const validatedAccount = accounts.find(({ id }) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        return id === accountId; | 
					 | 
					 | 
					        return id === accountId; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      }); | 
					 | 
					 | 
					      }); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -342,17 +358,7 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return activities; | 
					 | 
					 | 
					    return activities; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  } | 
					 | 
					 | 
					  } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					  private isUniqueAccount(accounts: AccountWithPlatform[]) { | 
					 | 
					 | 
					  private async extendActivitiesWithErrors({ | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					    const uniqueAccountIds = new Set<string>(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    for (const account of accounts) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					      uniqueAccountIds.add(account.id); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    return uniqueAccountIds.size === 1; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  private async markActivitiesAsDuplicates({ | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    activitiesDto, | 
					 | 
					 | 
					    activitiesDto, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    userId | 
					 | 
					 | 
					    userId | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  }: { | 
					 | 
					 | 
					  }: { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -428,6 +434,16 @@ export class ImportService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    ); | 
					 | 
					 | 
					    ); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  } | 
					 | 
					 | 
					  } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  private isUniqueAccount(accounts: AccountWithPlatform[]) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    const uniqueAccountIds = new Set<string>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    for (const account of accounts) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      uniqueAccountIds.add(account.id); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    return uniqueAccountIds.size === 1; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					  } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					  private async validateActivities({ | 
					 | 
					 | 
					  private async validateActivities({ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    activitiesDto, | 
					 | 
					 | 
					    activitiesDto, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    maxActivitiesToImport, | 
					 | 
					 | 
					    maxActivitiesToImport, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |