From 2a15762f1079a50967798629ffbb2c7deec8bc4c Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 11 Dec 2021 21:08:20 +0100 Subject: [PATCH] Remove default transactions import limit --- apps/api/src/app/import/import.service.ts | 14 ++++++++++---- apps/api/src/services/configuration.service.ts | 1 + .../services/interfaces/environment.interface.ts | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 59df401bd..cf9f6f705 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -1,4 +1,5 @@ import { OrderService } from '@ghostfolio/api/app/order/order.service'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { Injectable } from '@nestjs/common'; import { Order } from '@prisma/client'; @@ -6,9 +7,8 @@ import { isSameDay, parseISO } from 'date-fns'; @Injectable() export class ImportService { - private static MAX_ORDERS_TO_IMPORT = 20; - public constructor( + private readonly configurationService: ConfigurationService, private readonly dataProviderService: DataProviderService, private readonly orderService: OrderService ) {} @@ -59,8 +59,14 @@ export class ImportService { orders: Partial[]; userId: string; }) { - if (orders?.length > ImportService.MAX_ORDERS_TO_IMPORT) { - throw new Error('Too many transactions'); + if ( + orders?.length > this.configurationService.get('MAX_ORDERS_TO_IMPORT') + ) { + throw new Error( + `Too many transactions (${this.configurationService.get( + 'MAX_ORDERS_TO_IMPORT' + )} at most)` + ); } const existingOrders = await this.orderService.orders({ diff --git a/apps/api/src/services/configuration.service.ts b/apps/api/src/services/configuration.service.ts index 1956a6b62..b2d9c65fb 100644 --- a/apps/api/src/services/configuration.service.ts +++ b/apps/api/src/services/configuration.service.ts @@ -27,6 +27,7 @@ export class ConfigurationService { GOOGLE_SECRET: str({ default: 'dummySecret' }), JWT_SECRET_KEY: str({}), MAX_ITEM_IN_CACHE: num({ default: 9999 }), + MAX_ORDERS_TO_IMPORT: num({ default: Number.MAX_SAFE_INTEGER }), PORT: port({ default: 3333 }), RAKUTEN_RAPID_API_KEY: str({ default: '' }), REDIS_HOST: str({ default: 'localhost' }), diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index e475d32ec..56f8fe822 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -18,6 +18,7 @@ export interface Environment extends CleanedEnvAccessors { GOOGLE_SECRET: string; JWT_SECRET_KEY: string; MAX_ITEM_IN_CACHE: number; + MAX_ORDERS_TO_IMPORT: number; PORT: number; RAKUTEN_RAPID_API_KEY: string; REDIS_HOST: string;