From 8643c868fd274b031b9198fdddeaf88c4df84982 Mon Sep 17 00:00:00 2001 From: rodrigobasilio2022 <114958722+rodrigobasilio2022@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:07:12 -0300 Subject: [PATCH] Adds containsAll validator (#5279) --- .../HangingProtocolService/lib/validator.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/core/src/services/HangingProtocolService/lib/validator.js b/platform/core/src/services/HangingProtocolService/lib/validator.js index 72c0a9549..e14670c01 100644 --- a/platform/core/src/services/HangingProtocolService/lib/validator.js +++ b/platform/core/src/services/HangingProtocolService/lib/validator.js @@ -227,6 +227,20 @@ validate.validators.contains = function (value, options, key) { return key + 'must contain ' + testValue; } }; + +// Custom validator: containsAll +// Checks that all items in testValue are present in value +validate.validators.containsAll = function (value, options, key) { + const testValue = getTestValue(options); + if (!Array.isArray(value) || !Array.isArray(testValue)) { + return `${key} must be an array and test value must be an array.`; + } + const missing = testValue.filter(item => !value.includes(item)); + if (missing.length > 0) { + return `${key} must contain all of: ${testValue.join(', ')}. Missing: ${missing.join(', ')}`; + } +}; + /** * @example * value = 'Attenuation Corrected'