From f48b63f218e225e2c737c360bd099826c43709b2 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Wed, 6 Aug 2025 20:58:06 +0200 Subject: [PATCH] Various improvements --- apps/api/src/app/import/import.service.ts | 26 ++++++++----------- .../app/services/import-activities.service.ts | 4 ++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index 0f6a0e198..a9fe898b9 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -300,30 +300,27 @@ export class ImportService { } if (tagsDto?.length) { - const existingTags = await this.tagService.getTagsForUser(user.id); + const existingTagsOfUser = await this.tagService.getTagsForUser(user.id); - const canCreateTag = hasPermission( - user.permissions, - permissions.createTag - ); const canCreateOwnTag = hasPermission( user.permissions, permissions.createOwnTag ); for (const tag of tagsDto) { - // Check if there is any existing tag - const existingTag = existingTags.find(({ name }) => { - return name === tag.name; + const existingTagOfUser = existingTagsOfUser.find(({ id }) => { + return id === tag.id; }); - // If there is no tag or if the tag belongs to a different user, then create a new tag - if (!existingTag || existingTag.userId !== user.id) { - if (!canCreateTag && !canCreateOwnTag) { - throw new Error('User does not have permission to create tags'); + if (!existingTagOfUser || existingTagOfUser.userId !== null) { + if (!canCreateOwnTag) { + throw new Error( + `Insufficient permissions to create custom tag ("${tag.name}")` + ); } if (!isDryRun) { + const existingTag = await this.tagService.getTag({ id: tag.id }); let oldTagId: string; if (existingTag) { @@ -338,7 +335,6 @@ export class ImportService { const newTag = await this.tagService.createTag(tagObject); - // Store the new to old tag ID mappings for updating activities if (existingTag && oldTagId) { tagIdMapping[oldTagId] = newTag.id; } @@ -667,7 +663,6 @@ export class ImportService { error, fee, quantity, - tagIds: tags, type, unitPrice, SymbolProfile: { @@ -684,7 +679,8 @@ export class ImportService { isActive: true, sectors: undefined, updatedAt: undefined - } + }, + tagIds: tags }; } ); diff --git a/apps/client/src/app/services/import-activities.service.ts b/apps/client/src/app/services/import-activities.service.ts index 3611170ac..27a34652b 100644 --- a/apps/client/src/app/services/import-activities.service.ts +++ b/apps/client/src/app/services/import-activities.service.ts @@ -163,7 +163,9 @@ export class ImportActivitiesService { dataSource: SymbolProfile.dataSource, date: date.toString(), symbol: SymbolProfile.symbol, - tags: tags?.map(({ id }) => id) + tags: tags?.map(({ id }) => { + return id; + }) }; }