{"ScriptPreparationCode":null,"TestCases":[{"Name":"reduce \u002B find","Code":"const asset = {\r\n \u0022id\u0022: \u0022d6341699-44d9-40d4-96a7-a9e6399790f4\u0022,\r\n \u0022equipmentFamily\u0022: \u002219XRV\u0022,\r\n \u0022picControllerVersion\u0022: \u0022PIC3\u0022,\r\n}\r\n\r\nconst telemetryResponse = {\r\n \u0022findTelemetry\u0022: {\r\n \u0022data\u0022: [{\r\n \u0022id\u0022: \u0022-\u0022,\r\n \u0022assetId\u0022: \u00229e54e15b-f7d8-4573-aa3a-aeed31ed1f40\u0022,\r\n \u0022timestamp\u0022: 1678968480000,\r\n \u0022brickClass\u0022: \u0022Alarm\u0022,\r\n \u0022measureName\u0022: \u0022al122\u0022,\r\n \u0022measureValue\u0022: true,\r\n \u0022createdAt\u0022: 1678982953477\r\n },\r\n {\r\n \u0022id\u0022: \u0022-\u0022,\r\n \u0022assetId\u0022: \u00229e54e15b-f7d8-4573-aa3a-aeed31ed1f40\u0022,\r\n \u0022timestamp\u0022: 1678970700000,\r\n \u0022brickClass\u0022: \u0022Alarm\u0022,\r\n \u0022measureName\u0022: \u0022al160\u0022,\r\n \u0022measureValue\u0022: true,\r\n \u0022createdAt\u0022: 1678985127307\r\n }\r\n ],\r\n \u0022limit\u0022: 1000\r\n }\r\n}\r\nconst alarmMetadataResponses = [{\r\n getAlarmMetaData: {\r\n data: [{\r\n alarmCode: \u0022239\u0022,\r\n chillerModel: \u002219XR\u0022,\r\n controllerType: \u0022PIC2\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 1,\r\n category: \u0022PROTECTIVE LIMIT\u0022,\r\n resetType: \u0022Manual\u0022,\r\n },\r\n {\r\n alarmCode: \u0022243\u0022,\r\n chillerModel: \u002219XR\u0022,\r\n controllerType: \u0022PIC2\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 3,\r\n category: \u0022POTENTIAL FREEZE- UP\u0022,\r\n resetType: \u0022Manual\u0022,\r\n },\r\n ],\r\n },\r\n}, {\r\n getAlarmMetaData: {\r\n data: [{\r\n alarmCode: \u0022253\u0022,\r\n chillerModel: \u002223XRV\u0022,\r\n controllerType: \u0022PIC3\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 1,\r\n category: \u0022PROTECTIVE LIMIT\u0022,\r\n resetType: \u0022Manual\u0022,\r\n }, ],\r\n },\r\n}, ];\r\nconst getMappedAlarms = () =\u003E {\r\n const alarms = telemetryResponse?.findTelemetry?.data ?? [];\r\n\r\n const assetAlarms = alarms.filter((alarm) =\u003E asset.id === alarm?.assetId \u0026\u0026 Boolean(alarm));\r\n\r\n const alarmMetadataArray = alarmMetadataResponses\r\n .reduce((acc, response) =\u003E {\r\n return [\r\n ...acc,\r\n ...(response?.getAlarmMetaData?.data ?? []).filter((metadata) =\u003E Boolean(metadata))\r\n ]\r\n }, []);\r\n\r\n return assetAlarms.map((alarm) =\u003E {\r\n \t const telemetryAlarmCode = alarm.measureName.replace(/\\D/g, \u0022\u0022);\r\n \r\n const isMetadataMatches = (alarmMetadata) =\u003E {\r\n const {\r\n chillerModel,\r\n controllerType,\r\n alarmCode\r\n } = alarmMetadata ?? {};\r\n if (!chillerModel \u0026\u0026 !controllerType \u0026\u0026 !alarmCode) {\r\n return false;\r\n }\r\n \r\n return (\r\n asset.equipmentFamily === chillerModel \u0026\u0026\r\n asset.picControllerVersion === controllerType \u0026\u0026\r\n telemetryAlarmCode === alarmCode\r\n );\r\n };\r\n \r\n const metadata = alarmMetadataArray.find((data) =\u003E isMetadataMatches(data));\r\n \r\n return getTransformedAlarm(alarm, metadata);\r\n })\r\n}\r\ngetMappedAlarms()","IsDeferred":false},{"Name":"save on find","Code":"const asset = {\r\n \u0022id\u0022: \u0022d6341699-44d9-40d4-96a7-a9e6399790f4\u0022,\r\n \u0022equipmentFamily\u0022: \u002219XRV\u0022,\r\n \u0022picControllerVersion\u0022: \u0022PIC3\u0022,\r\n}\r\n\r\nconst telemetryResponse = {\r\n \u0022findTelemetry\u0022: {\r\n \u0022data\u0022: [{\r\n \u0022id\u0022: \u0022-\u0022,\r\n \u0022assetId\u0022: \u00229e54e15b-f7d8-4573-aa3a-aeed31ed1f40\u0022,\r\n \u0022timestamp\u0022: 1678968480000,\r\n \u0022brickClass\u0022: \u0022Alarm\u0022,\r\n \u0022measureName\u0022: \u0022al122\u0022,\r\n \u0022measureValue\u0022: true,\r\n \u0022createdAt\u0022: 1678982953477\r\n },\r\n {\r\n \u0022id\u0022: \u0022-\u0022,\r\n \u0022assetId\u0022: \u00229e54e15b-f7d8-4573-aa3a-aeed31ed1f40\u0022,\r\n \u0022timestamp\u0022: 1678970700000,\r\n \u0022brickClass\u0022: \u0022Alarm\u0022,\r\n \u0022measureName\u0022: \u0022al160\u0022,\r\n \u0022measureValue\u0022: true,\r\n \u0022createdAt\u0022: 1678985127307\r\n }\r\n ],\r\n \u0022limit\u0022: 1000\r\n }\r\n}\r\nconst alarmMetadataResponses = [{\r\n getAlarmMetaData: {\r\n data: [{\r\n alarmCode: \u0022239\u0022,\r\n chillerModel: \u002219XR\u0022,\r\n controllerType: \u0022PIC2\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 1,\r\n category: \u0022PROTECTIVE LIMIT\u0022,\r\n resetType: \u0022Manual\u0022,\r\n },\r\n {\r\n alarmCode: \u0022243\u0022,\r\n chillerModel: \u002219XR\u0022,\r\n controllerType: \u0022PIC2\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 3,\r\n category: \u0022POTENTIAL FREEZE- UP\u0022,\r\n resetType: \u0022Manual\u0022,\r\n },\r\n ],\r\n },\r\n}, {\r\n getAlarmMetaData: {\r\n data: [{\r\n alarmCode: \u0022253\u0022,\r\n chillerModel: \u002223XRV\u0022,\r\n controllerType: \u0022PIC3\u0022,\r\n type: \u0022Alarm\u0022,\r\n level: 1,\r\n category: \u0022PROTECTIVE LIMIT\u0022,\r\n resetType: \u0022Manual\u0022,\r\n }, ],\r\n },\r\n}, ];\r\nconst getMappedAlarms = () =\u003E {\r\n const alarms = telemetryResponse?.findTelemetry?.data ?? [];\r\n\r\n const assetAlarms = alarms.filter((alarm) =\u003E asset.id === alarm?.assetId \u0026\u0026 Boolean(alarm));\r\n\r\n return assetAlarms.map((alarm) =\u003E {\r\n const telemetryAlarmCode = alarm.measureName.replace(/\\D/g, \u0022\u0022);\r\n\r\n const isMetadataMatches = (alarmMetadata) =\u003E {\r\n const {\r\n chillerModel,\r\n controllerType,\r\n alarmCode\r\n } = alarmMetadata ?? {};\r\n if (!chillerModel \u0026\u0026 !controllerType \u0026\u0026 !alarmCode) {\r\n return false;\r\n }\r\n\r\n return (\r\n asset.equipmentFamily === chillerModel \u0026\u0026\r\n asset.picControllerVersion === controllerType \u0026\u0026\r\n telemetryAlarmCode === alarmCode\r\n );\r\n };\r\n\r\n const metadata = null;\r\n\r\n alarmMetadataResponses.find((response) =\u003E {\r\n const metadata = response?.getAlarmMetaData?.data?.find((data) =\u003E isMetadataMatches(data));\r\n return metadata;\r\n });\r\n\r\n return getTransformedAlarm(alarm, metadata);\r\n })\r\n}\r\ngetMappedAlarms()\r\n","IsDeferred":false}]}