refactor: cleanup loops over object keys
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index a3b78ca63ec8e40d44a07c7a12f9689ed38eee63..4ea134b6ef062d5860e2b36e29d8d7d29b794781 100644 (file)
@@ -23,7 +23,13 @@ import {
   type ResponseCallback,
   type ResponseType,
 } from '../../types';
-import { Constants, Utils, handleSendMessageError, logger } from '../../utils';
+import {
+  Constants,
+  cloneObject,
+  handleSendMessageError,
+  logger,
+  promiseWithTimeout,
+} from '../../utils';
 
 const moduleName = 'OCPPRequestService';
 
@@ -191,7 +197,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     if (this.jsonSchemas.has(commandName as RequestCommand) === false) {
@@ -201,7 +207,7 @@ export abstract class OCPPRequestService {
       return true;
     }
     const validate = this.ajv.compile(this.jsonSchemas.get(commandName as RequestCommand));
-    payload = Utils.cloneObject<T>(payload);
+    payload = cloneObject<T>(payload);
     OCPPServiceUtils.convertDateToISOString<T>(payload);
     if (validate(payload)) {
       return true;
@@ -224,7 +230,7 @@ export abstract class OCPPRequestService {
     commandName: RequestCommand | IncomingRequestCommand,
     payload: T
   ): boolean {
-    if (chargingStation.getPayloadSchemaValidation() === false) {
+    if (chargingStation.getOcppStrictCompliance() === false) {
       return true;
     }
     if (
@@ -242,7 +248,7 @@ export abstract class OCPPRequestService {
         commandName as IncomingRequestCommand
       )
     );
-    payload = Utils.cloneObject<T>(payload);
+    payload = cloneObject<T>(payload);
     OCPPServiceUtils.convertDateToISOString<T>(payload);
     if (validate(payload)) {
       return true;
@@ -284,7 +290,7 @@ export abstract class OCPPRequestService {
       // eslint-disable-next-line @typescript-eslint/no-this-alias
       const self = this;
       // Send a message through wsConnection
-      return Utils.promiseWithTimeout(
+      return promiseWithTimeout(
         new Promise((resolve, reject) => {
           /**
            * Function that will receive the request's response