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 { 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 }
}

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

Loading…
Cancel
Save