From: Jérôme Benoit Date: Sat, 7 Jan 2023 16:38:33 +0000 (+0100) Subject: Move date conversion to ISO string helper to utils class X-Git-Tag: v1.1.89~18 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1799761a204a0cafc55637e33434babb739865b2;p=e-mobility-charging-stations-simulator.git Move date conversion to ISO string helper to utils class Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 6b58e2ad..fda320ab 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -140,7 +140,7 @@ export default abstract class OCPPRequestService { return true; } const validate = this.ajv.compile(schema); - this.convertDateToISOString(payload); + OCPPServiceUtils.convertDateToISOString(payload); if (validate(payload)) { return true; } @@ -385,16 +385,6 @@ export default abstract class OCPPRequestService { } } - private convertDateToISOString(obj: T): void { - for (const k in obj) { - if (obj[k] instanceof Date) { - (obj as JsonObject)[k] = (obj[k] as Date).toISOString(); - } else if (obj[k] !== null && typeof obj[k] === 'object') { - this.convertDateToISOString(obj[k] as T); - } - } - } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public abstract requestHandler( chargingStation: ChargingStation, diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 33637c65..574476c6 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1,6 +1,7 @@ import type { DefinedError, ErrorObject } from 'ajv'; import BaseError from '../../exception/BaseError'; +import type { JsonObject, JsonType } from '../../types/JsonType'; import type { SampledValueTemplate } from '../../types/MeasurandPerPhaseSampledValueTemplates'; import { StandardParametersKey } from '../../types/ocpp/Configuration'; import { ErrorType } from '../../types/ocpp/ErrorType'; @@ -104,6 +105,16 @@ export class OCPPServiceUtils { return true; } + public static convertDateToISOString(obj: T): void { + for (const k in obj) { + if (obj[k] instanceof Date) { + (obj as JsonObject)[k] = (obj[k] as Date).toISOString(); + } else if (obj[k] !== null && typeof obj[k] === 'object') { + this.convertDateToISOString(obj[k] as T); + } + } + } + protected static getSampledValueTemplate( chargingStation: ChargingStation, connectorId: number,