Browse Source

Change tags to tagIds in import and export

pull/5420/head
Thomas Kaul 4 months ago
parent
commit
04a70a46cd
  1. 2
      apps/api/src/app/export/export.service.ts
  2. 11
      apps/api/src/app/import/import.service.ts
  3. 2
      apps/api/src/app/order/create-order.dto.ts
  4. 2
      apps/api/src/app/order/order.controller.ts
  5. 2
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts
  6. 8
      apps/client/src/app/services/import-activities.service.ts
  7. 11
      libs/common/src/lib/interfaces/export.interface.ts
  8. 2
      test/import/ok/500-activities.json
  9. 4
      test/import/ok/btceur.json
  10. 4
      test/import/ok/btcusd.json
  11. 2
      test/import/ok/derived-currency.json
  12. 17
      test/import/ok/sample.json
  13. 2
      test/import/ok/vti-buy-long-history.json

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

@ -237,7 +237,7 @@ export class ExportService {
dataSource: SymbolProfile.dataSource, dataSource: SymbolProfile.dataSource,
date: date.toISOString(), date: date.toISOString(),
symbol: SymbolProfile.symbol, symbol: SymbolProfile.symbol,
tags: currentTags.map(({ id: tagId }) => { tagId: currentTags.map(({ id: tagId }) => {
return tagId; return tagId;
}) })
}; };

11
apps/api/src/app/import/import.service.ts

@ -365,7 +365,7 @@ export class ImportService {
} }
// If a new tag is created, then update the tag ID in all activities // If a new tag is created, then update the tag ID in all activities
activity.tags = (activity.tags ?? []).map((tagId) => { activity.tagIds = (activity.tagIds ?? []).map((tagId) => {
return tagIdMapping[tagId] ?? tagId; return tagIdMapping[tagId] ?? tagId;
}); });
} }
@ -630,7 +630,7 @@ export class ImportService {
fee, fee,
quantity, quantity,
symbol, symbol,
tags, tagIds,
type, type,
unitPrice unitPrice
}) => { }) => {
@ -663,6 +663,7 @@ export class ImportService {
error, error,
fee, fee,
quantity, quantity,
tagIds,
type, type,
unitPrice, unitPrice,
SymbolProfile: { SymbolProfile: {
@ -679,8 +680,7 @@ export class ImportService {
isActive: true, isActive: true,
sectors: undefined, sectors: undefined,
updatedAt: undefined updatedAt: undefined
}, }
tagIds: tags
}; };
} }
); );
@ -745,7 +745,8 @@ export class ImportService {
} }
} }
if (!assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })]) { if (assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })]) {
} else {
const assetProfile = { const assetProfile = {
currency, currency,
...( ...(

2
apps/api/src/app/order/create-order.dto.ts

@ -64,7 +64,7 @@ export class CreateOrderDto {
@IsArray() @IsArray()
@IsOptional() @IsOptional()
tags?: string[]; tagIds?: string[];
@IsEnum(Type, { each: true }) @IsEnum(Type, { each: true })
type: Type; type: Type;

2
apps/api/src/app/order/order.controller.ts

@ -217,7 +217,7 @@ export class OrderController {
} }
} }
}, },
tags: data.tags?.map((id) => { tags: data.tagIds?.map((id) => {
return { id }; return { id };
}), }),
user: { connect: { id: this.request.user.id } }, user: { connect: { id: this.request.user.id } },

2
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts

@ -523,7 +523,7 @@ export class GfCreateOrUpdateActivityDialog implements OnDestroy {
? undefined ? undefined
: this.activityForm.get('searchSymbol')?.value?.symbol) ?? : this.activityForm.get('searchSymbol')?.value?.symbol) ??
this.activityForm.get('name')?.value, this.activityForm.get('name')?.value,
tags: this.activityForm.get('tags').value?.map(({ id }) => { tagIds: this.activityForm.get('tags').value?.map(({ id }) => {
return id; return id;
}), }),
type: this.activityForm.get('type').value, type: this.activityForm.get('type').value,

8
apps/client/src/app/services/import-activities.service.ts

@ -146,7 +146,7 @@ export class ImportActivitiesService {
fee, fee,
quantity, quantity,
SymbolProfile, SymbolProfile,
tags, tagIds,
type, type,
unitPrice, unitPrice,
updateAccountBalance updateAccountBalance
@ -156,16 +156,14 @@ export class ImportActivitiesService {
comment, comment,
fee, fee,
quantity, quantity,
tagIds,
type, type,
unitPrice, unitPrice,
updateAccountBalance, updateAccountBalance,
currency: currency ?? SymbolProfile.currency, currency: currency ?? SymbolProfile.currency,
dataSource: SymbolProfile.dataSource, dataSource: SymbolProfile.dataSource,
date: date.toString(), date: date.toString(),
symbol: SymbolProfile.symbol, symbol: SymbolProfile.symbol
tags: tags?.map(({ id }) => {
return id;
})
}; };
} }

11
libs/common/src/lib/interfaces/export.interface.ts

@ -1,7 +1,8 @@
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { import {
Account, Account,
DataSource, DataSource,
Order,
Platform, Platform,
SymbolProfile, SymbolProfile,
Tag Tag
@ -15,14 +16,20 @@ export interface Export {
balances: AccountBalance[]; balances: AccountBalance[];
})[]; })[];
activities: (Omit< activities: (Omit<
Order, Activity,
| 'accountUserId' | 'accountUserId'
| 'createdAt' | 'createdAt'
| 'date' | 'date'
| 'feeInAssetProfileCurrency'
| 'feeInBaseCurrency'
| 'isDraft' | 'isDraft'
| 'symbolProfileId' | 'symbolProfileId'
| 'tags'
| 'unitPriceInAssetProfileCurrency'
| 'updatedAt' | 'updatedAt'
| 'userId' | 'userId'
| 'value'
| 'valueInBaseCurrency'
> & { dataSource: DataSource; date: string; symbol: string })[]; > & { dataSource: DataSource; date: string; symbol: string })[];
assetProfiles: (Omit< assetProfiles: (Omit<
SymbolProfile, SymbolProfile,

2
test/import/ok/500-activities.json

@ -14,7 +14,7 @@
} }
], ],
"platforms": [], "platforms": [],
"tags": [], "tagIds": [],
"activities": [ "activities": [
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",

4
test/import/ok/btceur.json

@ -5,7 +5,7 @@
}, },
"accounts": [], "accounts": [],
"platforms": [], "platforms": [],
"tags": [], "tagIds": [],
"activities": [ "activities": [
{ {
"accountId": null, "accountId": null,
@ -18,7 +18,7 @@
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-12-12T00:00:00.000Z", "date": "2021-12-12T00:00:00.000Z",
"symbol": "BTCUSD", "symbol": "BTCUSD",
"tags": [] "tagIds": []
} }
], ],
"user": { "user": {

4
test/import/ok/btcusd.json

@ -5,7 +5,7 @@
}, },
"accounts": [], "accounts": [],
"platforms": [], "platforms": [],
"tags": [], "tagIds": [],
"activities": [ "activities": [
{ {
"accountId": null, "accountId": null,
@ -18,7 +18,7 @@
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-12-12T00:00:00.000Z", "date": "2021-12-12T00:00:00.000Z",
"symbol": "BTCUSD", "symbol": "BTCUSD",
"tags": [] "tagIds": []
} }
], ],
"user": { "user": {

2
test/import/ok/derived-currency.json

@ -14,7 +14,7 @@
} }
], ],
"platforms": [], "platforms": [],
"tags": [], "tagIds": [],
"activities": [ "activities": [
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",

17
test/import/ok/sample.json

@ -77,7 +77,12 @@
"url": "https://interactivebrokers.com" "url": "https://interactivebrokers.com"
} }
], ],
"tags": [], "tagIds": [
{
"id": "7314654b-46a7-48a4-b6b9-4895b45ea107",
"name": "CORE"
}
],
"activities": [ "activities": [
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
@ -90,7 +95,7 @@
"dataSource": "MANUAL", "dataSource": "MANUAL",
"date": "2021-09-01T00:00:00.000Z", "date": "2021-09-01T00:00:00.000Z",
"symbol": "14a69cb9-1e31-43fa-b320-83703d8ed74b", "symbol": "14a69cb9-1e31-43fa-b320-83703d8ed74b",
"tags": [] "tagIds": []
}, },
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
@ -103,7 +108,7 @@
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-09-16T00:00:00.000Z", "date": "2021-09-16T00:00:00.000Z",
"symbol": "MSFT", "symbol": "MSFT",
"tags": [] "tagIds": ["7314654b-46a7-48a4-b6b9-4895b45ea107"]
}, },
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
@ -116,7 +121,7 @@
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-11-17T00:00:00.000Z", "date": "2021-11-17T00:00:00.000Z",
"symbol": "MSFT", "symbol": "MSFT",
"tags": [] "tagIds": ["7314654b-46a7-48a4-b6b9-4895b45ea107"]
}, },
{ {
"accountId": null, "accountId": null,
@ -129,7 +134,7 @@
"dataSource": "MANUAL", "dataSource": "MANUAL",
"date": "2022-01-01T00:00:00.000Z", "date": "2022-01-01T00:00:00.000Z",
"symbol": "7e91b7d4-1430-4212-8380-289a06c9bbc1", "symbol": "7e91b7d4-1430-4212-8380-289a06c9bbc1",
"tags": [] "tagIds": []
}, },
{ {
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", "accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0",
@ -142,7 +147,7 @@
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2050-06-06T00:00:00.000Z", "date": "2050-06-06T00:00:00.000Z",
"symbol": "MSFT", "symbol": "MSFT",
"tags": [] "tagIds": ["7314654b-46a7-48a4-b6b9-4895b45ea107"]
} }
], ],
"user": { "user": {

2
test/import/ok/vti-buy-long-history.json

@ -5,7 +5,7 @@
}, },
"accounts": [], "accounts": [],
"platforms": [], "platforms": [],
"tags": [], "tagIds": [],
"activities": [ "activities": [
{ {
"fee": 0, "fee": 0,

Loading…
Cancel
Save