fix: ensure no null serialized values end in UI server response payload
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 17:11:28 +0000 (18:11 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 17:11:28 +0000 (18:11 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ui-server/ui-services/AbstractUIService.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[],
       }),
     };
   }
index d7595c26db164589e1cfb807812fab72be7a3c0b..d0478b99573c2da29de611e05dba6a737bf21d84 100644 (file)
@@ -163,7 +163,7 @@ export abstract class AbstractUIService {
     if (isNotEmptyArray(payload.hashIds)) {
       payload.hashIds = payload.hashIds
         ?.map((hashId) => {
-          if (this.uiServer.chargingStations.has(hashId) === true) {
+          if (hashId !== undefined && this.uiServer.chargingStations.has(hashId) === true) {
             return hashId;
           }
           const msg = `${this.logPrefix(