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

4
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;
})
};
}

Loading…
Cancel
Save