From 3b68e4162f8c9a67bc598c2ea4cab407611e0d31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 7 Mar 2024 15:18:22 +0100 Subject: [PATCH] refactor: add sanity checks at adding charging station(s) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 2 +- .../ui-server/ui-services/AbstractUIService.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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, -- 2.34.1