From: Jérôme Benoit Date: Thu, 30 Nov 2023 17:11:28 +0000 (+0100) Subject: fix: ensure no null serialized values end in UI server response payload X-Git-Tag: v1.2.28~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=31fdd918e146f6d4f534ea3df5b3ceace0e23cfc;p=e-mobility-charging-stations-simulator.git fix: ensure no null serialized values end in UI server response payload Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts index b385be7f..d3282916 100644 --- a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts @@ -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[], }), }; } diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index d7595c26..d0478b99 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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(