|
@ -1,4 +1,5 @@ |
|
|
import { OrderService } from '@ghostfolio/api/app/order/order.service'; |
|
|
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 { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Order } from '@prisma/client'; |
|
|
import { Order } from '@prisma/client'; |
|
@ -6,9 +7,8 @@ import { isSameDay, parseISO } from 'date-fns'; |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class ImportService { |
|
|
export class ImportService { |
|
|
private static MAX_ORDERS_TO_IMPORT = 20; |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
public constructor( |
|
|
|
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly dataProviderService: DataProviderService, |
|
|
private readonly dataProviderService: DataProviderService, |
|
|
private readonly orderService: OrderService |
|
|
private readonly orderService: OrderService |
|
|
) {} |
|
|
) {} |
|
@ -59,8 +59,14 @@ export class ImportService { |
|
|
orders: Partial<Order>[]; |
|
|
orders: Partial<Order>[]; |
|
|
userId: string; |
|
|
userId: string; |
|
|
}) { |
|
|
}) { |
|
|
if (orders?.length > ImportService.MAX_ORDERS_TO_IMPORT) { |
|
|
if ( |
|
|
throw new Error('Too many transactions'); |
|
|
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({ |
|
|
const existingOrders = await this.orderService.orders({ |
|
|