refactor: add sanity checks at adding charging station(s)
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / AbstractUIService.ts
index de83c6b7e4eb85adaa3e2d5297393482c3d8feb6..07bb2cdb150888d9623d60eb1355531a67c24e71 100644 (file)
@@ -242,6 +242,19 @@ export abstract class AbstractUIService {
       numberOfStations: number
       options?: ChargingStationOptions
     }
+    if (!Bootstrap.getInstance().getState().started) {
+      return {
+        status: ResponseStatus.FAILURE,
+        errorMessage:
+          'Cannot add charging station(s) while the charging stations simulator is not started'
+      } satisfies ResponsePayload
+    }
+    if (typeof template !== 'string' || typeof numberOfStations !== 'number') {
+      return {
+        status: ResponseStatus.FAILURE,
+        errorMessage: 'Invalid request payload'
+      } satisfies ResponsePayload
+    }
     if (!this.uiServer.chargingStationTemplates.has(template)) {
       return {
         status: ResponseStatus.FAILURE,