Browse Source

refactor

pull/5287/head
Attila Cseh 3 weeks ago
parent
commit
bba57a98f5
  1. 19
      apps/api/src/app/import/import.service.ts

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

@ -302,17 +302,6 @@ export class ImportService {
if (tagsDto?.length) { if (tagsDto?.length) {
const existingTags = await this.tagService.getTagsForUser(user.id); const existingTags = await this.tagService.getTagsForUser(user.id);
for (const tag of tagsDto) {
// Check if there is any existing tag
const existingTag = existingTags.find(({ name }) => {
return name === tag.name;
});
// If there is no tag or if the tag belongs to a different user, then create a new tag
if (
!existingTag ||
(existingTag.userId && existingTag.userId !== user.id)
) {
const canCreateTag = hasPermission( const canCreateTag = hasPermission(
user.permissions, user.permissions,
permissions.createTag permissions.createTag
@ -322,6 +311,14 @@ export class ImportService {
permissions.createOwnTag permissions.createOwnTag
); );
for (const tag of tagsDto) {
// Check if there is any existing tag
const existingTag = existingTags.find(({ name }) => {
return name === tag.name;
});
// 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) { if (!canCreateTag && !canCreateOwnTag) {
throw new Error('User does not have permission to create tags'); throw new Error('User does not have permission to create tags');
} }

Loading…
Cancel
Save