mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
@ -519,6 +519,23 @@ export class TagModelService {
|
||||
// Extract tags marked for addition in spaceTags
|
||||
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
|
||||
const commonTagUuids = new Set(
|
||||
spaceTagsToAdd
|
||||
@ -536,11 +553,25 @@ export class TagModelService {
|
||||
);
|
||||
|
||||
// Modify subspaceModels by removing tags with UUIDs present in commonTagUuids
|
||||
const modifiedSubspaces = subspaceModels.map((subspace) => ({
|
||||
let modifiedSubspaces = subspaceModels.map((subspace) => ({
|
||||
...subspace,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -543,6 +543,23 @@ export class TagService {
|
||||
// Extract tags marked for addition in spaceTags
|
||||
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
|
||||
const commonTagUuids = new Set(
|
||||
spaceTagsToAdd
|
||||
@ -560,11 +577,25 @@ export class TagService {
|
||||
);
|
||||
|
||||
// Modify subspaceModels by removing tags with UUIDs present in commonTagUuids
|
||||
const modifiedSubspaces = subspaceModels.map((subspace) => ({
|
||||
let modifiedSubspaces = subspaceModels.map((subspace) => ({
|
||||
...subspace,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user