Skip to content

Commit

Permalink
ISSUE #4641 remove entry if there's no objects
Browse files Browse the repository at this point in the history
  • Loading branch information
carmenfan committed Jan 18, 2024
1 parent 88cf4f5 commit 8d8206d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions backend/src/v4/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,20 @@ function clean(groupData) {
cleanArray(groupData, "transformation");

if(groupData.objects) {
groupData.objects = groupData.objects.filter(({shared_ids, ...extIds}, i) => {
const shouldKeep = shared_ids || getCommonElements(Object.keys(extIds), Object.values(idTypes)).length;

if(shouldKeep) {
Object.values(idTypes).forEach((idType) => {
if (groupData.objects[i][idType]) {
cleanArray(groupData.objects[i], idType);
}
});

cleanArray(groupData.objects[i], "shared_ids");
if (groupData.objects[i].shared_ids) {
groupData.objects[i].shared_ids = groupData.objects[i].shared_ids.map(utils.uuidToString);
groupData.objects = groupData.objects.filter((entry) => {

Object.values([...Object.values(idTypes), "shared_ids"]).forEach((idType) => {
if (entry[idType]) {
cleanArray(entry, idType);
}
});

if (entry.shared_ids) {
entry.shared_ids = entry.shared_ids.map(utils.uuidToString);
return true;
}

return shouldKeep;
return getCommonElements(Object.keys(entry), Object.values(idTypes)).length;
});
}

Expand Down

0 comments on commit 8d8206d

Please sign in to comment.