diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e613f3b6..68dab494c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Removed the alias from the user interface as a preparation to remove it from the `User` database schema +- Removed the activities import limit for users with a subscription + +### Todo + +- Rename the environment variable from `MAX_ORDERS_TO_IMPORT` to `MAX_ACTIVITIES_TO_IMPORT` ## 1.169.0 - 14.07.2022 diff --git a/apps/api/src/app/import/import.controller.ts b/apps/api/src/app/import/import.controller.ts index 00350f819..422e1cb9f 100644 --- a/apps/api/src/app/import/import.controller.ts +++ b/apps/api/src/app/import/import.controller.ts @@ -34,8 +34,20 @@ export class ImportController { ); } + let maxActivitiesToImport = this.configurationService.get( + 'MAX_ACTIVITIES_TO_IMPORT' + ); + + if ( + this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') && + this.request.user.subscription.type === 'Premium' + ) { + maxActivitiesToImport = Number.MAX_SAFE_INTEGER; + } + try { return await this.importService.import({ + maxActivitiesToImport, activities: importData.activities, userId: this.request.user.id }); diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 40d677d9b..3eb424469 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -17,9 +17,11 @@ export class ImportService { public async import({ activities, + maxActivitiesToImport, userId }: { activities: Partial[]; + maxActivitiesToImport: number; userId: string; }): Promise { for (const activity of activities) { @@ -32,7 +34,11 @@ export class ImportService { } } - await this.validateActivities({ activities, userId }); + await this.validateActivities({ + activities, + maxActivitiesToImport, + userId + }); const accountIds = (await this.accountService.getAccounts(userId)).map( (account) => { @@ -81,19 +87,15 @@ export class ImportService { private async validateActivities({ activities, + maxActivitiesToImport, userId }: { activities: Partial[]; + maxActivitiesToImport: number; userId: string; }) { - if ( - activities?.length > this.configurationService.get('MAX_ORDERS_TO_IMPORT') - ) { - throw new Error( - `Too many activities (${this.configurationService.get( - 'MAX_ORDERS_TO_IMPORT' - )} at most)` - ); + if (activities?.length > maxActivitiesToImport) { + throw new Error(`Too many activities (${maxActivitiesToImport} at most)`); } const existingActivities = await this.orderService.orders({ diff --git a/apps/api/src/services/configuration.service.ts b/apps/api/src/services/configuration.service.ts index a187f4138..e9367e2ab 100644 --- a/apps/api/src/services/configuration.service.ts +++ b/apps/api/src/services/configuration.service.ts @@ -33,8 +33,8 @@ export class ConfigurationService { GOOGLE_SHEETS_PRIVATE_KEY: str({ default: '' }), HOST: host({ default: '0.0.0.0' }), JWT_SECRET_KEY: str({}), + MAX_ACTIVITIES_TO_IMPORT: num({ default: Number.MAX_SAFE_INTEGER }), 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: host({ default: 'localhost' }), diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index 6d7058be3..00db1e2b6 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -23,8 +23,8 @@ export interface Environment extends CleanedEnvAccessors { GOOGLE_SHEETS_ID: string; GOOGLE_SHEETS_PRIVATE_KEY: string; JWT_SECRET_KEY: string; + MAX_ACTIVITIES_TO_IMPORT: number; MAX_ITEM_IN_CACHE: number; - MAX_ORDERS_TO_IMPORT: number; PORT: number; RAKUTEN_RAPID_API_KEY: string; REDIS_HOST: string; diff --git a/apps/client/src/app/pages/portfolio/transactions/import-transaction-dialog/import-transaction-dialog.html b/apps/client/src/app/pages/portfolio/transactions/import-transaction-dialog/import-transaction-dialog.html index 604eb7c06..b8069e849 100644 --- a/apps/client/src/app/pages/portfolio/transactions/import-transaction-dialog/import-transaction-dialog.html +++ b/apps/client/src/app/pages/portfolio/transactions/import-transaction-dialog/import-transaction-dialog.html @@ -1,6 +1,6 @@