Skip to content

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

Feature/improve import json file validation (#455)

Thomas Kaulb6902e10ea35
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 651bcd3335..0e7b075088 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Changed
+
+- Improved the validation of `json` files in the import functionality for transactions
+
## 1.69.0 - 07.11.2021
### Added
diff --git a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts
index ac73a81026..67ef12b1a0 100644
--- a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts
+++ b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts
@@ -12,6 +12,7 @@ import { User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { DataSource, Order as OrderModel } from '@prisma/client';
import { format, parseISO } from 'date-fns';
+import { isArray } from 'lodash';
import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@@ -189,6 +190,11 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
try {
if (file.type === 'application/json') {
const content = JSON.parse(fileContent);
+
+ if (!isArray(content.orders)) {
+ throw new Error();
+ }
+
try {
await this.importTransactionsService.importJson({
content: content.orders,