feat(ui): use toggle button to star/stop simulator
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / AbstractUIService.ts
index fbca016bed65fd3cf0d4a4ac3563fafa7105e514..de83c6b7e4eb85adaa3e2d5297393482c3d8feb6 100644 (file)
@@ -76,6 +76,7 @@ export abstract class AbstractUIService {
       [ProcedureName.LIST_CHARGING_STATIONS, this.handleListChargingStations.bind(this)],
       [ProcedureName.ADD_CHARGING_STATIONS, this.handleAddChargingStations.bind(this)],
       [ProcedureName.PERFORMANCE_STATISTICS, this.handlePerformanceStatistics.bind(this)],
+      [ProcedureName.SIMULATOR_STATE, this.handleSimulatorState.bind(this)],
       [ProcedureName.START_SIMULATOR, this.handleStartSimulator.bind(this)],
       [ProcedureName.STOP_SIMULATOR, this.handleStopSimulator.bind(this)]
     ])
@@ -98,7 +99,7 @@ export abstract class AbstractUIService {
 
       if (!this.requestHandlers.has(command)) {
         throw new BaseError(
-          `${command} is not implemented to handle message payload ${JSON.stringify(
+          `'${command}' is not implemented to handle message payload ${JSON.stringify(
             requestPayload,
             undefined,
             2
@@ -295,6 +296,21 @@ export abstract class AbstractUIService {
     }
   }
 
+  private handleSimulatorState (): ResponsePayload {
+    try {
+      return {
+        status: ResponseStatus.SUCCESS,
+        state: Bootstrap.getInstance().getState()
+      } satisfies ResponsePayload
+    } catch (error) {
+      return {
+        status: ResponseStatus.FAILURE,
+        errorMessage: (error as Error).message,
+        errorStack: (error as Error).stack
+      } satisfies ResponsePayload
+    }
+  }
+
   private async handleStartSimulator (): Promise<ResponsePayload> {
     try {
       await Bootstrap.getInstance().start()