From: Jérôme Benoit Date: Thu, 7 Mar 2024 14:18:22 +0000 (+0100) Subject: refactor: add sanity checks at adding charging station(s) X-Git-Tag: v1.3.0~33 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3b68e4162f8c9a67bc598c2ea4cab407611e0d31;p=e-mobility-charging-stations-simulator.git refactor: add sanity checks at adding charging station(s) Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 80470d00..40d451ed 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -539,7 +539,7 @@ export class Bootstrap extends EventEmitter { ): Promise { if (!this.started && !this.starting) { throw new BaseError( - 'Cannot add a charging station while charging stations simulator is not started' + 'Cannot add charging station while charging stations simulator is not started' ) } await this.workerImplementation?.addElement({ diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index de83c6b7..07bb2cdb 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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,