Skip to content

Commit aaae517

Browse files
committed
Add convertNullToUndefined function
1 parent ae22f69 commit aaae517

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

x-pack/plugins/alerting/server/saved_objects/migrations.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SavedObjectMigrationFn,
1212
SavedObjectMigrationContext,
1313
SavedObjectAttributes,
14+
SavedObjectAttribute,
1415
} from '../../../../../src/core/server';
1516
import { RawAlert, RawAlertAction } from '../types';
1617
import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
@@ -342,6 +343,10 @@ function restructureConnectorsThatSupportIncident(
342343
};
343344
}
344345

346+
function convertNullToUndefined(attribute: SavedObjectAttribute) {
347+
return attribute != null ? attribute : undefined;
348+
}
349+
345350
function removeNullsFromSecurityRules(
346351
doc: SavedObjectUnsanitizedDoc<RawAlert>
347352
): SavedObjectUnsanitizedDoc<RawAlert> {
@@ -354,20 +359,20 @@ function removeNullsFromSecurityRules(
354359
...doc.attributes,
355360
params: {
356361
...params,
357-
buildingBlockType: params.buildingBlockType != null ? params.buildingBlockType : undefined,
358-
note: params.note != null ? params.note : undefined,
359-
index: params.index != null ? params.index : undefined,
360-
language: params.language != null ? params.language : undefined,
361-
license: params.license != null ? params.license : undefined,
362-
outputIndex: params.outputIndex != null ? params.outputIndex : undefined,
363-
savedId: params.savedId != null ? params.savedId : undefined,
364-
timelineId: params.timelineId != null ? params.timelineId : undefined,
365-
timelineTitle: params.timelineTitle != null ? params.timelineTitle : undefined,
366-
meta: params.meta != null ? params.meta : undefined,
367-
query: params.query != null ? params.query : undefined,
368-
filters: params.filters != null ? params.filters : undefined,
362+
buildingBlockType: convertNullToUndefined(params.buildingBlockType),
363+
note: convertNullToUndefined(params.note),
364+
index: convertNullToUndefined(params.index),
365+
language: convertNullToUndefined(params.language),
366+
license: convertNullToUndefined(params.license),
367+
outputIndex: convertNullToUndefined(params.outputIndex),
368+
savedId: convertNullToUndefined(params.savedId),
369+
timelineId: convertNullToUndefined(params.timelineId),
370+
timelineTitle: convertNullToUndefined(params.timelineTitle),
371+
meta: convertNullToUndefined(params.meta),
372+
query: convertNullToUndefined(params.query),
373+
filters: convertNullToUndefined(params.filters),
369374
riskScoreMapping: params.riskScoreMapping != null ? params.riskScoreMapping : [],
370-
ruleNameOverride: params.ruleNameOverride != null ? params.ruleNameOverride : undefined,
375+
ruleNameOverride: convertNullToUndefined(params.ruleNameOverride),
371376
severityMapping: params.severityMapping != null ? params.severityMapping : [],
372377
threat: params.threat != null ? params.threat : [],
373378
threshold:
@@ -385,7 +390,7 @@ function removeNullsFromSecurityRules(
385390
params.threshold.cardinality != null ? params.threshold.cardinality : [],
386391
}
387392
: undefined,
388-
timestampOverride: params.timestampOverride != null ? params.timestampOverride : undefined,
393+
timestampOverride: convertNullToUndefined(params.timestampOverride),
389394
exceptionsList:
390395
params.exceptionsList != null
391396
? params.exceptionsList
@@ -394,7 +399,7 @@ function removeNullsFromSecurityRules(
394399
: params.lists != null
395400
? params.lists
396401
: [],
397-
threatFilters: params.threatFilters != null ? params.threatFilters : undefined,
402+
threatFilters: convertNullToUndefined(params.threatFilters),
398403
},
399404
},
400405
};

0 commit comments

Comments
 (0)