Browse Source

Various improvements

pull/5287/head
Thomas Kaul 2 weeks ago
parent
commit
f48b63f218
  1. 26
      apps/api/src/app/import/import.service.ts
  2. 4
      apps/client/src/app/services/import-activities.service.ts

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

@ -300,30 +300,27 @@ export class ImportService {
} }
if (tagsDto?.length) { 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( const canCreateOwnTag = hasPermission(
user.permissions, user.permissions,
permissions.createOwnTag permissions.createOwnTag
); );
for (const tag of tagsDto) { for (const tag of tagsDto) {
// Check if there is any existing tag const existingTagOfUser = existingTagsOfUser.find(({ id }) => {
const existingTag = existingTags.find(({ name }) => { return id === tag.id;
return name === tag.name;
}); });
// If there is no tag or if the tag belongs to a different user, then create a new tag if (!existingTagOfUser || existingTagOfUser.userId !== null) {
if (!existingTag || existingTag.userId !== user.id) { if (!canCreateOwnTag) {
if (!canCreateTag && !canCreateOwnTag) { throw new Error(
throw new Error('User does not have permission to create tags'); `Insufficient permissions to create custom tag ("${tag.name}")`
);
} }
if (!isDryRun) { if (!isDryRun) {
const existingTag = await this.tagService.getTag({ id: tag.id });
let oldTagId: string; let oldTagId: string;
if (existingTag) { if (existingTag) {
@ -338,7 +335,6 @@ export class ImportService {
const newTag = await this.tagService.createTag(tagObject); const newTag = await this.tagService.createTag(tagObject);
// Store the new to old tag ID mappings for updating activities
if (existingTag && oldTagId) { if (existingTag && oldTagId) {
tagIdMapping[oldTagId] = newTag.id; tagIdMapping[oldTagId] = newTag.id;
} }
@ -667,7 +663,6 @@ export class ImportService {
error, error,
fee, fee,
quantity, quantity,
tagIds: tags,
type, type,
unitPrice, unitPrice,
SymbolProfile: { SymbolProfile: {
@ -684,7 +679,8 @@ export class ImportService {
isActive: true, isActive: true,
sectors: undefined, sectors: undefined,
updatedAt: undefined updatedAt: undefined
} },
tagIds: tags
}; };
} }
); );

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

@ -163,7 +163,9 @@ export class ImportActivitiesService {
dataSource: SymbolProfile.dataSource, dataSource: SymbolProfile.dataSource,
date: date.toString(), date: date.toString(),
symbol: SymbolProfile.symbol, symbol: SymbolProfile.symbol,
tags: tags?.map(({ id }) => id) tags: tags?.map(({ id }) => {
return id;
})
}; };
} }

Loading…
Cancel
Save