diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 9c0c7a6fb..8162e4e1f 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -1,6 +1,7 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { OrderService } from '@ghostfolio/api/app/order/order.service'; import { environment } from '@ghostfolio/api/environments/environment'; +import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { Filter, Export } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; @@ -9,7 +10,8 @@ import { Injectable } from '@nestjs/common'; export class ExportService { public constructor( private readonly accountService: AccountService, - private readonly orderService: OrderService + private readonly orderService: OrderService, + private readonly tagService: TagService ) {} public async export({ @@ -43,6 +45,19 @@ export class ExportService { }; } ); + const allTags = ( + await this.tagService.getTags({ + orderBy: { + name: 'asc' + }, + where: { userId } + }) + ).map(({ id, name }) => { + return { + id, + name + }; + }); let { activities } = await this.orderService.getOrders({ filters, @@ -72,9 +87,9 @@ export class ExportService { id, quantity, SymbolProfile, + tags, type, - unitPrice, - tags + unitPrice }) => { return { accountId, @@ -82,6 +97,9 @@ export class ExportService { fee, id, quantity, + tags: tags.map(({ id: tagId }) => { + return tagId; + }), type, unitPrice, currency: SymbolProfile.currency, @@ -93,11 +111,11 @@ export class ExportService { type === 'ITEM' || type === 'LIABILITY' ? SymbolProfile.name - : SymbolProfile.symbol, - tags: tags.map(({ id: tagId }) => tagId) + : SymbolProfile.symbol }; } ), + tags: allTags, user: { settings: { currency: userCurrency } } diff --git a/libs/common/src/lib/interfaces/export.interface.ts b/libs/common/src/lib/interfaces/export.interface.ts index de3d7cf02..3623e70dc 100644 --- a/libs/common/src/lib/interfaces/export.interface.ts +++ b/libs/common/src/lib/interfaces/export.interface.ts @@ -1,4 +1,4 @@ -import { Account, Order } from '@prisma/client'; +import { Account, Order, Tag } from '@prisma/client'; export interface Export { meta: { @@ -16,5 +16,6 @@ export interface Export { | 'updatedAt' | 'userId' > & { date: string; symbol: string })[]; + tags: Omit[]; user: { settings: { currency: string } }; }