Skip to content

Commit

Permalink
[backend] fix stix_id upsert (#6559)
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact authored and SamuelHassine committed Apr 18, 2024
1 parent 8c57ac7 commit 45d9737
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2445,13 +2445,12 @@ const upsertElement = async (context, user, element, type, basePatch, opts = {})
const updatePatch = { ...basePatch };
// Handle attributes updates
if (isNotEmptyField(basePatch.stix_id) || isNotEmptyField(basePatch.x_opencti_stix_ids)) {
const compareIds = [element.standard_id, generateStandardId(type, basePatch)];
const ids = [...(basePatch.x_opencti_stix_ids || [])];
if (isNotEmptyField(basePatch.stix_id) && !compareIds.includes(basePatch.stix_id)) {
ids.push(basePatch.stix_id);
const idsToAdd = [...(basePatch.x_opencti_stix_ids || [])];
if (isNotEmptyField(basePatch.stix_id) && basePatch.stix_id !== element.standard_id && !idsToAdd.includes(basePatch.stix_id)) {
idsToAdd.push(basePatch.stix_id);
}
if (ids.length > 0) {
updatePatch.x_opencti_stix_ids = ids;
if (idsToAdd.length > 0) {
updatePatch.x_opencti_stix_ids = idsToAdd;
}
}
// Cumulate creator id
Expand Down

0 comments on commit 45d9737

Please sign in to comment.