fix: ensure no null serialized values end in UI server response payload
[e-mobility-charging-stations-simulator.git] / src / charging-station / broadcast-channel / UIServiceWorkerBroadcastChannel.ts
index b385be7fc47aae52e67eaac792dc4f59256c81a1..d328291636ac8da6f37ce6fc1eebca288e67d339 100644 (file)
@@ -70,31 +70,31 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
       status: responsesStatus,
       hashIdsSucceeded: this.responses
         .get(uuid)
-        ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId))
-        .map(({ status, hashId }) => {
-          if (status === ResponseStatus.SUCCESS) {
+        ?.responses.map(({ status, hashId }) => {
+          if (hashId !== undefined && status === ResponseStatus.SUCCESS) {
             return hashId;
           }
-        }) as string[],
+        })
+        .filter((hashId) => !isNullOrUndefined(hashId)) as string[],
       ...(responsesStatus === ResponseStatus.FAILURE && {
         hashIdsFailed: this.responses
           .get(uuid)
-          ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId))
-          .map(({ status, hashId }) => {
-            if (status === ResponseStatus.FAILURE) {
+          ?.responses.map(({ status, hashId }) => {
+            if (hashId !== undefined && status === ResponseStatus.FAILURE) {
               return hashId;
             }
-          }) as string[],
+          })
+          .filter((hashId) => !isNullOrUndefined(hashId)) as string[],
       }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         responsesFailed: this.responses
           .get(uuid)
-          ?.responses.filter((response) => !isNullOrUndefined(response))
-          .map((response) => {
-            if (response.status === ResponseStatus.FAILURE) {
+          ?.responses.map((response) => {
+            if (response !== undefined && response.status === ResponseStatus.FAILURE) {
               return response;
             }
-          }) as BroadcastChannelResponsePayload[],
+          })
+          .filter((response) => !isNullOrUndefined(response)) as BroadcastChannelResponsePayload[],
       }),
     };
   }