From: Jérôme Benoit Date: Sat, 23 Mar 2024 00:09:14 +0000 (+0100) Subject: refactor: cleanup app message handling code X-Git-Tag: v1.3.1~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9e9194c977f2100a92a4549e6562750499607706;p=e-mobility-charging-stations-simulator.git refactor: cleanup app message handling code Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index c13eb1b1..0f2a26a8 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -376,38 +376,35 @@ export class Bootstrap extends EventEmitter { // 2 // )}` // ) + const { event, data } = msg try { - switch (msg.event) { + switch (event) { case ChargingStationWorkerMessageEvents.added: - this.emit(ChargingStationWorkerMessageEvents.added, msg.data) + this.emit(ChargingStationWorkerMessageEvents.added, data) break case ChargingStationWorkerMessageEvents.deleted: - this.emit(ChargingStationWorkerMessageEvents.deleted, msg.data) + this.emit(ChargingStationWorkerMessageEvents.deleted, data) break case ChargingStationWorkerMessageEvents.started: - this.emit(ChargingStationWorkerMessageEvents.started, msg.data) + this.emit(ChargingStationWorkerMessageEvents.started, data) break case ChargingStationWorkerMessageEvents.stopped: - this.emit(ChargingStationWorkerMessageEvents.stopped, msg.data) + this.emit(ChargingStationWorkerMessageEvents.stopped, data) break case ChargingStationWorkerMessageEvents.updated: - this.emit(ChargingStationWorkerMessageEvents.updated, msg.data) + this.emit(ChargingStationWorkerMessageEvents.updated, data) break case ChargingStationWorkerMessageEvents.performanceStatistics: - this.emit(ChargingStationWorkerMessageEvents.performanceStatistics, msg.data) + this.emit(ChargingStationWorkerMessageEvents.performanceStatistics, data) break default: throw new BaseError( - `Unknown charging station worker event: '${ - msg.event - }' received with data: ${JSON.stringify(msg.data, undefined, 2)}` + `Unknown charging station worker event: '${event}' received with data: ${JSON.stringify(data, undefined, 2)}` ) } } catch (error) { logger.error( - `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${ - msg.event - }' event:`, + `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${event}' event:`, error ) }