|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import { AccountService } from '@ghostfolio/api/app/account/account.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';
|
|
|
|
@ -8,6 +9,7 @@ import { isSameDay, parseISO } from 'date-fns';
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ImportService {
|
|
|
|
|
public constructor(
|
|
|
|
|
private readonly accountService: AccountService,
|
|
|
|
|
private readonly configurationService: ConfigurationService,
|
|
|
|
|
private readonly dataProviderService: DataProviderService,
|
|
|
|
|
private readonly orderService: OrderService
|
|
|
|
@ -32,6 +34,12 @@ export class ImportService {
|
|
|
|
|
|
|
|
|
|
await this.validateOrders({ orders, userId });
|
|
|
|
|
|
|
|
|
|
const accountIds = (await this.accountService.getAccounts(userId)).map(
|
|
|
|
|
(account) => {
|
|
|
|
|
return account.id;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for (const {
|
|
|
|
|
accountId,
|
|
|
|
|
currency,
|
|
|
|
@ -44,7 +52,6 @@ export class ImportService {
|
|
|
|
|
unitPrice
|
|
|
|
|
} of orders) {
|
|
|
|
|
await this.orderService.createOrder({
|
|
|
|
|
accountId,
|
|
|
|
|
currency,
|
|
|
|
|
dataSource,
|
|
|
|
|
fee,
|
|
|
|
@ -53,6 +60,7 @@ export class ImportService {
|
|
|
|
|
type,
|
|
|
|
|
unitPrice,
|
|
|
|
|
userId,
|
|
|
|
|
accountId: accountIds.includes(accountId) ? accountId : undefined,
|
|
|
|
|
date: parseISO(<string>(<unknown>date)),
|
|
|
|
|
SymbolProfile: {
|
|
|
|
|
connectOrCreate: {
|
|
|
|
|