Merge pull request #253 from SyncrowIOT/dev

Dev
This commit is contained in:
hannathkadher
2025-02-06 09:26:54 +04:00
committed by GitHub
2 changed files with 64 additions and 2 deletions

View File

@ -519,6 +519,23 @@ export class TagModelService {
// Extract tags marked for addition in spaceTags // Extract tags marked for addition in spaceTags
const spaceTagsToAdd = spaceTags.filter((tag) => tag.action === 'add'); const spaceTagsToAdd = spaceTags.filter((tag) => tag.action === 'add');
const subspaceTagsToAdd = subspaceModels.flatMap(
(subspace) => subspace.tags?.filter((tag) => tag.action === 'add') || [],
);
const subspaceTagsToDelete = subspaceModels.flatMap(
(subspace) =>
subspace.tags?.filter((tag) => tag.action === 'delete') || [],
);
const subspaceTagsToDeleteUuids = new Set(
subspaceTagsToDelete.map((tag) => tag.uuid),
);
const commonTagsInSubspaces = subspaceTagsToAdd.filter((tag) =>
subspaceTagsToDeleteUuids.has(tag.uuid),
);
// Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion // Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion
const commonTagUuids = new Set( const commonTagUuids = new Set(
spaceTagsToAdd spaceTagsToAdd
@ -536,11 +553,25 @@ export class TagModelService {
); );
// Modify subspaceModels by removing tags with UUIDs present in commonTagUuids // Modify subspaceModels by removing tags with UUIDs present in commonTagUuids
const modifiedSubspaces = subspaceModels.map((subspace) => ({ let modifiedSubspaces = subspaceModels.map((subspace) => ({
...subspace, ...subspace,
tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [], tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [],
})); }));
modifiedSubspaces = modifiedSubspaces.map((subspace) => ({
...subspace,
tags:
subspace.tags?.filter(
(tag) =>
!(
tag.action === 'delete' &&
commonTagsInSubspaces.some(
(commonTag) => commonTag.uuid === tag.uuid,
)
),
) || [],
}));
return modifiedSubspaces; return modifiedSubspaces;
} }
} }

View File

@ -543,6 +543,23 @@ export class TagService {
// Extract tags marked for addition in spaceTags // Extract tags marked for addition in spaceTags
const spaceTagsToAdd = spaceTags?.filter((tag) => tag.action === 'add'); const spaceTagsToAdd = spaceTags?.filter((tag) => tag.action === 'add');
const subspaceTagsToAdd = subspaceModels.flatMap(
(subspace) => subspace.tags?.filter((tag) => tag.action === 'add') || [],
);
const subspaceTagsToDelete = subspaceModels.flatMap(
(subspace) =>
subspace.tags?.filter((tag) => tag.action === 'delete') || [],
);
const subspaceTagsToDeleteUuids = new Set(
subspaceTagsToDelete.map((tag) => tag.uuid),
);
const commonTagsInSubspaces = subspaceTagsToAdd.filter((tag) =>
subspaceTagsToDeleteUuids.has(tag.uuid),
);
// Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion // Find UUIDs of tags that are common between spaceTagsToAdd and subspace tags marked for deletion
const commonTagUuids = new Set( const commonTagUuids = new Set(
spaceTagsToAdd spaceTagsToAdd
@ -560,11 +577,25 @@ export class TagService {
); );
// Modify subspaceModels by removing tags with UUIDs present in commonTagUuids // Modify subspaceModels by removing tags with UUIDs present in commonTagUuids
const modifiedSubspaces = subspaceModels.map((subspace) => ({ let modifiedSubspaces = subspaceModels.map((subspace) => ({
...subspace, ...subspace,
tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [], tags: subspace.tags?.filter((tag) => !commonTagUuids.has(tag.uuid)) || [],
})); }));
modifiedSubspaces = modifiedSubspaces.map((subspace) => ({
...subspace,
tags:
subspace.tags?.filter(
(tag) =>
!(
tag.action === 'delete' &&
commonTagsInSubspaces.some(
(commonTag) => commonTag.uuid === tag.uuid,
)
),
) || [],
}));
return modifiedSubspaces; return modifiedSubspaces;
} }
} }