X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2Fui-services%2FAbstractUIService.ts;h=416d660d7d5f4c6ead5a5f003c528f13d69b0c9e;hb=4b9332afad3ebdd1c7b7e3e98dc1a9fcefebc04f;hp=799a6651b23eb7a1089283997bd05cec56e639f7;hpb=0c9f0f67eb80d625536f4bc8a1cea58e00f35c2f;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 799a6651..416d660d 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -12,7 +12,7 @@ import { type ResponsePayload, ResponseStatus } from '../../../types/index.js' -import { isNotEmptyArray, logger } from '../../../utils/index.js' +import { isAsyncFunction, isNotEmptyArray, logger } from '../../../utils/index.js' import { Bootstrap } from '../../Bootstrap.js' import { UIServiceWorkerBroadcastChannel } from '../../broadcast-channel/UIServiceWorkerBroadcastChannel.js' import type { AbstractUIServer } from '../AbstractUIServer.js' @@ -93,7 +93,18 @@ export abstract class AbstractUIService { // Call the request handler to build the response payload // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - responsePayload = await this.requestHandlers.get(command)!(messageId, command, requestPayload) + const requestHandler = this.requestHandlers.get(command)! + if (isAsyncFunction(requestHandler)) { + responsePayload = await requestHandler(messageId, command, requestPayload) + } else { + responsePayload = ( + requestHandler as ( + uuid?: string, + procedureName?: ProcedureName, + payload?: RequestPayload + ) => undefined | ResponsePayload + )(messageId, command, requestPayload) + } } catch (error) { // Log logger.error(`${this.logPrefix(moduleName, 'requestHandler')} Handle request error:`, error) @@ -163,7 +174,7 @@ export abstract class AbstractUIService { ): void { if (isNotEmptyArray(payload.hashIds)) { payload.hashIds = payload.hashIds - ?.map((hashId) => { + .map(hashId => { if (this.uiServer.chargingStations.has(hashId)) { return hashId } @@ -175,7 +186,7 @@ export abstract class AbstractUIService { ) return undefined }) - .filter((hashId) => hashId != null) as string[] + .filter(hashId => hashId != null) as string[] } else { delete payload.hashIds }