Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/fix import validation for numbers equal zero (#875)

Thomas Kaul4dc76817ce8f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 922ec6848b..039c54432d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Fixed the import validation for numbers equal 0
- Fixed the color of the spinner in the activities filter component (dark mode)
## 1.143.0 - 26.04.2022
diff --git a/apps/client/src/app/services/import-transactions.service.ts b/apps/client/src/app/services/import-transactions.service.ts
index 8557fe0af7..1d5670a323 100644
--- a/apps/client/src/app/services/import-transactions.service.ts
+++ b/apps/client/src/app/services/import-transactions.service.ts
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { Account, DataSource, Type } from '@prisma/client';
import { parse } from 'date-fns';
-import { isNumber } from 'lodash';
+import { isFinite } from 'lodash';
import { parse as csvToJson } from 'papaparse';
import { EMPTY } from 'rxjs';
import { catchError } from 'rxjs/operators';
@@ -185,7 +185,7 @@ export class ImportTransactionsService {
item = this.lowercaseKeys(item);
for (const key of ImportTransactionsService.FEE_KEYS) {
- if ((item[key] || item[key] === 0) && isNumber(item[key])) {
+ if (isFinite(item[key])) {
return item[key];
}
}
@@ -208,7 +208,7 @@ export class ImportTransactionsService {
item = this.lowercaseKeys(item);
for (const key of ImportTransactionsService.QUANTITY_KEYS) {
- if (item[key] && isNumber(item[key])) {
+ if (isFinite(item[key])) {
return item[key];
}
}
@@ -288,7 +288,7 @@ export class ImportTransactionsService {
item = this.lowercaseKeys(item);
for (const key of ImportTransactionsService.UNIT_PRICE_KEYS) {
- if (item[key] && isNumber(item[key])) {
+ if (isFinite(item[key])) {
return item[key];
}
}
diff --git a/test/import/ok.csv b/test/import/ok.csv
index ddefbc93fd..2d27422ab7 100644
--- a/test/import/ok.csv
+++ b/test/import/ok.csv
@@ -2,3 +2,4 @@ Date,Code,Currency,Price,Quantity,Action,Fee
17/11/2021,MSFT,USD,0.62,5,dividend,0.00
16/09/2021,MSFT,USD,298.580,5,buy,19.00
01/01/2022,Penthouse Apartment,USD,500000.0,1,item,0.00
+06/06/2050,MSFT,USD,0.00,0,buy,0.00
diff --git a/test/import/ok.json b/test/import/ok.json
index ae08aee732..63961be744 100644
--- a/test/import/ok.json
+++ b/test/import/ok.json
@@ -5,34 +5,43 @@
},
"activities": [
{
- "accountId": null,
- "date": "2021-12-31T23:00:00.000Z",
+ "fee": 0,
+ "quantity": 0,
+ "type": "BUY",
+ "unitPrice": 0,
+ "currency": "USD",
+ "dataSource": "YAHOO",
+ "date": "2050-06-05T22:00:00.000Z",
+ "symbol": "MSFT"
+ },
+ {
"fee": 0,
"quantity": 1,
"type": "ITEM",
"unitPrice": 500000,
"currency": "USD",
"dataSource": "MANUAL",
+ "date": "2021-12-31T22:00:00.000Z",
"symbol": "Penthouse Apartment"
},
{
- "date": "2021-11-16T23:00:00.000Z",
"fee": 0,
"quantity": 5,
"type": "DIVIDEND",
"unitPrice": 0.62,
"currency": "USD",
"dataSource": "YAHOO",
+ "date": "2021-11-16T22:00:00.000Z",
"symbol": "MSFT"
},
{
- "date": "2021-09-15T22:00:00.000Z",
"fee": 19,
"quantity": 5,
"type": "BUY",
"unitPrice": 298.58,
"currency": "USD",
"dataSource": "YAHOO",
+ "date": "2021-09-15T22:00:00.000Z",
"symbol": "MSFT"
}
]