Skip to content

Commit 6aeb8ef

Browse files
committed
ISSUE #4641 address feedback
1 parent 089d946 commit 6aeb8ef

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

backend/src/v4/models/group.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,24 @@ function clean(groupData) {
100100
cleanArray(groupData, "rules");
101101
cleanArray(groupData, "transformation");
102102

103-
for (let i = 0; groupData.objects && i < groupData.objects.length; i++) {
104-
Object.values(idTypes).forEach((idType) => {
105-
if (groupData.objects[i][idType]) {
106-
cleanArray(groupData.objects[i], idType);
103+
if(groupData.objects) {
104+
groupData.objects = groupData.objects.filter(({shared_ids, ...extIds}, i) => {
105+
const shouldKeep = shared_ids || getCommonElements(Object.keys(extIds), Object.values(idTypes)).length;
106+
107+
if(shouldKeep) {
108+
Object.values(idTypes).forEach((idType) => {
109+
if (groupData.objects[i][idType]) {
110+
cleanArray(groupData.objects[i], idType);
111+
}
112+
});
113+
114+
if (groupData.objects[i].shared_ids) {
115+
cleanArray(groupData.objects[i], "shared_ids");
116+
groupData.objects[i].shared_ids = groupData.objects[i].shared_ids.map(x => utils.uuidToString(x));
117+
}
107118
}
108-
});
109119

110-
if (groupData.objects[i].shared_ids) {
111-
cleanArray(groupData.objects[i], "shared_ids");
112-
groupData.objects[i].shared_ids = groupData.objects[i].shared_ids.map(x => utils.uuidToString(x));
113-
}
114-
}
115-
116-
if(groupData.objects) {
117-
groupData.objects = groupData.objects.filter(({shared_ids, ...extIds}) => {
118-
return shared_ids || Object.keys(extIds).some((v) => Object.values(idTypes).includes(v));
120+
return shouldKeep;
119121
});
120122
}
121123

@@ -132,8 +134,7 @@ async function getObjectIds(account, model, branch, revId, groupData, convertSha
132134
if (groupData.rules && groupData.rules.length > 0) {
133135
return Meta.findObjectIdsByRules(account, model, groupData.rules, branch, revId, convertSharedIDsToString, showIfcGuids);
134136
} else {
135-
const res = await getObjectsArray(model, branch, revId, groupData, convertSharedIDsToString, showIfcGuids);
136-
return res;
137+
return getObjectsArray(model, branch, revId, groupData, convertSharedIDsToString, showIfcGuids);
137138
}
138139
}
139140

@@ -142,10 +143,10 @@ async function getObjectsArray(model, branch, revId, groupData, convertSharedIDs
142143
return Promise.all(groupData.objects.map(async({account, model:container, shared_ids, ...extIds}) => {
143144

144145
if (showIfcGuids) {
145-
if (extIds[idTypes.IFC]) {
146-
return {account, model: container, [idTypes.IFC]: extIds[idTypes.IFC]};
146+
if (!shared_ids) {
147+
// if we're storing other external Ids, just return empty array (not converting).
148+
return {account, model: container, [idTypes.IFC]: extIds[idTypes.IFC] ?? []};
147149
}
148-
return {account, model: container, [idTypes.IFC]: []};
149150
} else if(shared_ids) {
150151
return {account, model: container, shared_ids: convertSharedIDsToString ? shared_ids.map(utils.uuidToString) : shared_ids.map(utils.stringToUUID)};
151152
}
@@ -199,16 +200,16 @@ function getObjectsArrayAsExternalIds(account, model, branch, rId, data) {
199200

200201
// have to have shared_ids, IFC or RVT ids, but not more than one
201202
if (
202-
(!containerEntry[idTypes.IFC] && !containerEntry[idTypes.RVT] && !containerEntry.shared_ids) &&
203-
!(containerEntry[idTypes.IFC] && !containerEntry[idTypes.RVT] && !containerEntry.shared_ids) &&
204-
!(!containerEntry[idTypes.IFC] && containerEntry[idTypes.RVT] && !containerEntry.shared_ids) &&
203+
(!containerEntry[idTypes.IFC] && !containerEntry[idTypes.RVT] && !containerEntry.shared_ids) ||
204+
!(containerEntry[idTypes.IFC] && !containerEntry[idTypes.RVT] && !containerEntry.shared_ids) ||
205+
!(!containerEntry[idTypes.IFC] && containerEntry[idTypes.RVT] && !containerEntry.shared_ids) ||
205206
!(!containerEntry[idTypes.IFC] && !containerEntry[idTypes.RVT] && containerEntry.shared_ids)
206207
) {
207208
return Promise.reject(responseCodes.INVALID_GROUP);
208209
}
209210

210211
if(!containerEntry.shared_ids) {
211-
return data;
212+
return containerEntry;
212213
}
213214

214215
try {

backend/src/v5/processors/teamspaces/projects/models/commons/tickets.groups.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ const getObjectArrayFromRules = async (teamspace, project, model, revId, rules,
6969

7070
if (!matched.length) return res;
7171

72-
const wantedIds = await getExternalIdsFromMetadata(matched);
72+
const wantedIds = getExternalIdsFromMetadata(matched);
7373

7474
if (wantedIds) {
7575
if (unwanted.length) {
76-
const unwantedIds = await getExternalIdsFromMetadata(unwanted, wantedIds.key);
76+
const unwantedIds = getExternalIdsFromMetadata(unwanted, wantedIds.key);
7777
if (unwantedIds) {
7878
wantedIds.values = getArrayDifference(unwantedIds.values, wantedIds.values);
7979
}
@@ -151,7 +151,7 @@ TicketGroups.addGroups = async (teamspace, project, model, ticket, groups) => {
151151
const convertedGroups = await Promise.all(groups.map(
152152
async (group) => {
153153
if (group.objects) {
154-
const objects = await convertToExternalIds(teamspace, project, group.objects, true);
154+
const objects = await convertToExternalIds(teamspace, project, group.objects);
155155
return { ...group, objects };
156156
}
157157

@@ -169,7 +169,7 @@ TicketGroups.updateTicketGroup = async (teamspace, project, model, ticket, group
169169
const convertedData = { ...data };
170170

171171
if (data.objects) {
172-
convertedData.objects = await convertToExternalIds(teamspace, project, data.objects, true);
172+
convertedData.objects = await convertToExternalIds(teamspace, project, data.objects);
173173
}
174174

175175
await updateGroup(teamspace, project, model, ticket, groupId, convertedData, author);

backend/tests/v5/unit/processors/teamspaces/projects/models/commons/scenes.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ const testSharedIdsToExternalIds = () => {
166166
expect(fn).toHaveBeenCalledTimes(1);
167167
expect(fn).toHaveBeenCalledWith(metaRes);
168168

169+
const externalIdKeys = Object.values(idTypesToKeys).flat();
170+
const query = { parents: { $in: sharedIds }, 'metadata.key': { $in: externalIdKeys }, rev_id: revId };
171+
const projection = { metadata: 1 };
172+
169173
expect(MetaModel.getMetadataByQuery).toHaveBeenCalledTimes(1);
170174
expect(MetaModel.getMetadataByQuery).toHaveBeenCalledWith(
171-
teamspace, container, expect.anything(), expect.anything());
175+
teamspace, container, query, projection);
172176
});
173177
});
174178
};

0 commit comments

Comments
 (0)