type ResponsePayload,
ResponseStatus
} from '../../../types/index.js'
-import { isNotEmptyArray, isNullOrUndefined, 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'
// 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)
errorDetails: (error as OCPPError).details
}
}
- if (!isNullOrUndefined(responsePayload)) {
+ if (responsePayload != null) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return this.uiServer.buildProtocolResponse(messageId!, responsePayload!)
+ return this.uiServer.buildProtocolResponse(messageId!, responsePayload)
}
}
): void {
if (isNotEmptyArray(payload.hashIds)) {
payload.hashIds = payload.hashIds
- ?.map((hashId) => {
- if (hashId !== undefined && this.uiServer.chargingStations.has(hashId)) {
+ .map(hashId => {
+ if (this.uiServer.chargingStations.has(hashId)) {
return hashId
}
logger.warn(
)
return undefined
})
- ?.filter((hashId) => !isNullOrUndefined(hashId)) as string[]
+ .filter(hashId => hashId != null) as string[]
} else {
delete payload.hashIds
}