diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e737092..c47194c07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added the cash balance and the value of equity to the account detail dialog +- Added a check for duplicates to the preview step of the import dividends dialog - Added an error message for duplicates to the preview step of the activities import - Added a connection timeout to the environment variable `DATABASE_URL` - Introduced the _Open Startup_ (`/open`) page with aggregated key metrics including uptime diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 8ab695ddf..3b45e3422 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -74,8 +74,25 @@ export class ImportService { 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 { Account, + error, quantity, value, accountId: Account?.id, @@ -83,7 +100,6 @@ export class ImportService { comment: undefined, createdAt: undefined, date: parseDate(dateString), - // TODO: Add evaluated error state fee: 0, feeInBaseCurrency: 0, id: assetProfile.id, @@ -208,7 +224,7 @@ export class ImportService { userId }); - const activitiesMarkedAsDuplicates = await this.markActivitiesAsDuplicates({ + const activitiesExtendedWithErrors = await this.extendActivitiesWithErrors({ activitiesDto, userId }); @@ -237,7 +253,7 @@ export class ImportService { SymbolProfile: assetProfile, type, unitPrice - } of activitiesMarkedAsDuplicates) { + } of activitiesExtendedWithErrors) { const validatedAccount = accounts.find(({ id }) => { return id === accountId; }); @@ -342,17 +358,7 @@ export class ImportService { return activities; } - private isUniqueAccount(accounts: AccountWithPlatform[]) { - const uniqueAccountIds = new Set(); - - for (const account of accounts) { - uniqueAccountIds.add(account.id); - } - - return uniqueAccountIds.size === 1; - } - - private async markActivitiesAsDuplicates({ + private async extendActivitiesWithErrors({ activitiesDto, userId }: { @@ -428,6 +434,16 @@ export class ImportService { ); } + private isUniqueAccount(accounts: AccountWithPlatform[]) { + const uniqueAccountIds = new Set(); + + for (const account of accounts) { + uniqueAccountIds.add(account.id); + } + + return uniqueAccountIds.size === 1; + } + private async validateActivities({ activitiesDto, maxActivitiesToImport,