Browse Source

feat(gh-4327): review fixes

pull/4337/head
Sayed Murtadha Ahmed 2 months ago
committed by Thomas Kaul
parent
commit
e76c191bfd
  1. 28
      apps/api/src/app/export/export.service.ts
  2. 3
      libs/common/src/lib/interfaces/export.interface.ts

28
apps/api/src/app/export/export.service.ts

@ -1,6 +1,7 @@
import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { AccountService } from '@ghostfolio/api/app/account/account.service';
import { OrderService } from '@ghostfolio/api/app/order/order.service'; import { OrderService } from '@ghostfolio/api/app/order/order.service';
import { environment } from '@ghostfolio/api/environments/environment'; import { environment } from '@ghostfolio/api/environments/environment';
import { TagService } from '@ghostfolio/api/services/tag/tag.service';
import { Filter, Export } from '@ghostfolio/common/interfaces'; import { Filter, Export } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
@ -9,7 +10,8 @@ import { Injectable } from '@nestjs/common';
export class ExportService { export class ExportService {
public constructor( public constructor(
private readonly accountService: AccountService, private readonly accountService: AccountService,
private readonly orderService: OrderService private readonly orderService: OrderService,
private readonly tagService: TagService
) {} ) {}
public async export({ 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({ let { activities } = await this.orderService.getOrders({
filters, filters,
@ -72,9 +87,9 @@ export class ExportService {
id, id,
quantity, quantity,
SymbolProfile, SymbolProfile,
tags,
type, type,
unitPrice, unitPrice
tags
}) => { }) => {
return { return {
accountId, accountId,
@ -82,6 +97,9 @@ export class ExportService {
fee, fee,
id, id,
quantity, quantity,
tags: tags.map(({ id: tagId }) => {
return tagId;
}),
type, type,
unitPrice, unitPrice,
currency: SymbolProfile.currency, currency: SymbolProfile.currency,
@ -93,11 +111,11 @@ export class ExportService {
type === 'ITEM' || type === 'ITEM' ||
type === 'LIABILITY' type === 'LIABILITY'
? SymbolProfile.name ? SymbolProfile.name
: SymbolProfile.symbol, : SymbolProfile.symbol
tags: tags.map(({ id: tagId }) => tagId)
}; };
} }
), ),
tags: allTags,
user: { user: {
settings: { currency: userCurrency } settings: { currency: userCurrency }
} }

3
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 { export interface Export {
meta: { meta: {
@ -16,5 +16,6 @@ export interface Export {
| 'updatedAt' | 'updatedAt'
| 'userId' | 'userId'
> & { date: string; symbol: string })[]; > & { date: string; symbol: string })[];
tags: Omit<Tag, 'userId'>[];
user: { settings: { currency: string } }; user: { settings: { currency: string } };
} }

Loading…
Cancel
Save