Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/extend export by tags (#4337)

Sayed Murtadha Ahmed05b0728b2ac7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3bb4e27be2..eac5249079 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
+### Added
+
+- Extended the export functionality by the tags
+
### Changed
- Upgraded `prettier` from version `3.4.2` to `3.5.1`
diff --git a/apps/api/src/app/export/export.module.ts b/apps/api/src/app/export/export.module.ts
index 048c60359b..892a761ccf 100644
--- a/apps/api/src/app/export/export.module.ts
+++ b/apps/api/src/app/export/export.module.ts
@@ -1,6 +1,7 @@
import { AccountModule } from '@ghostfolio/api/app/account/account.module';
import { OrderModule } from '@ghostfolio/api/app/order/order.module';
import { ApiModule } from '@ghostfolio/api/services/api/api.module';
+import { TagModule } from '@ghostfolio/api/services/tag/tag.module';
import { Module } from '@nestjs/common';
@@ -8,7 +9,7 @@ import { ExportController } from './export.controller';
import { ExportService } from './export.service';
@Module({
- imports: [AccountModule, ApiModule, OrderModule],
+ imports: [AccountModule, ApiModule, OrderModule, TagModule],
controllers: [ExportController],
providers: [ExportService]
})
diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts
index 1ff18ce9ca..219ffffda7 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({
@@ -60,9 +62,21 @@ export class ExportService {
});
}
+ const tags = (await this.tagService.getTagsForUser(userId))
+ .filter(({ isUsed }) => {
+ return isUsed;
+ })
+ .map(({ id, name }) => {
+ return {
+ id,
+ name
+ };
+ });
+
return {
meta: { date: new Date().toISOString(), version: environment.version },
accounts,
+ tags,
activities: activities.map(
({
accountId,
@@ -72,6 +86,7 @@ export class ExportService {
id,
quantity,
SymbolProfile,
+ tags: currentTags,
type,
unitPrice
}) => {
@@ -86,13 +101,12 @@ export class ExportService {
currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource,
date: date.toISOString(),
- symbol:
- type === 'FEE' ||
- type === 'INTEREST' ||
- type === 'ITEM' ||
- type === 'LIABILITY'
- ? SymbolProfile.name
- : SymbolProfile.symbol
+ symbol: ['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(type)
+ ? SymbolProfile.name
+ : SymbolProfile.symbol,
+ tags: currentTags.map(({ id: tagId }) => {
+ return tagId;
+ })
};
}
),
diff --git a/libs/common/src/lib/interfaces/export.interface.ts b/libs/common/src/lib/interfaces/export.interface.ts
index de3d7cf025..1257e50bcc 100644
--- a/libs/common/src/lib/interfaces/export.interface.ts
+++ b/libs/common/src/lib/interfaces/export.interface.ts
@@ -1,10 +1,6 @@
-import { Account, Order } from '@prisma/client';
+import { Account, Order, Tag } from '@prisma/client';
export interface Export {
- meta: {
- date: string;
- version: string;
- };
accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[];
activities: (Omit<
Order,
@@ -16,5 +12,10 @@ export interface Export {
| 'updatedAt'
| 'userId'
> & { date: string; symbol: string })[];
+ meta: {
+ date: string;
+ version: string;
+ };
+ tags: Omit<Tag, 'userId'>[];
user: { settings: { currency: string } };
}