Browse Source

Feature/check for duplicates in dividend import (#1986)

* Check for duplicates in dividend import

* Update changelog
pull/1987/head
Thomas Kaul 1 year ago
committed by GitHub
parent
commit
5bca8de44e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 44
      apps/api/src/app/import/import.service.ts

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Added the cash balance and the value of equity to the account detail dialog - 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 an error message for duplicates to the preview step of the activities import
- Added a connection timeout to the environment variable `DATABASE_URL` - Added a connection timeout to the environment variable `DATABASE_URL`
- Introduced the _Open Startup_ (`/open`) page with aggregated key metrics including uptime - Introduced the _Open Startup_ (`/open`) page with aggregated key metrics including uptime

44
apps/api/src/app/import/import.service.ts

@ -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,

Loading…
Cancel
Save