From 1799761a204a0cafc55637e33434babb739865b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 7 Jan 2023 17:38:33 +0100 Subject: [PATCH] Move date conversion to ISO string helper to utils class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ocpp/OCPPRequestService.ts | 12 +----------- src/charging-station/ocpp/OCPPServiceUtils.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) 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, -- 2.34.1