build(deps-dev): apply udpates
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPIncomingRequestService.ts
index 0ccf92fe78990be826da78d6da556df98c00dfc8..4b27f9d82f8de91b38bd1a19c4a826ebe6800d6b 100644 (file)
@@ -89,13 +89,10 @@ export abstract class OCPPIncomingRequestService extends AsyncResource {
     schema: JSONSchemaType<T>,
     payload: T,
   ): boolean {
-    if (chargingStation.getOcppStrictCompliance() === false) {
+    if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true;
     }
-    if (this.jsonValidateFunctions.has(commandName) === false) {
-      this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
-    }
-    const validate = this.jsonValidateFunctions.get(commandName)!;
+    const validate = this.getJsonIncomingRequestValidateFunction<T>(commandName, schema);
     if (validate(payload)) {
       return true;
     }
@@ -104,7 +101,7 @@ export abstract class OCPPIncomingRequestService extends AsyncResource {
       validate.errors,
     );
     throw new OCPPError(
-      OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+      OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
       'Incoming request PDU is invalid',
       commandName,
       JSON.stringify(validate.errors, undefined, 2),
@@ -118,6 +115,16 @@ export abstract class OCPPIncomingRequestService extends AsyncResource {
     return OCPPConstants.OCPP_RESPONSE_REJECTED;
   }
 
+  private getJsonIncomingRequestValidateFunction<T extends JsonType>(
+    commandName: IncomingRequestCommand,
+    schema: JSONSchemaType<T>,
+  ) {
+    if (this.jsonValidateFunctions.has(commandName) === false) {
+      this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
+    }
+    return this.jsonValidateFunctions.get(commandName)!;
+  }
+
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
   public abstract incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
     chargingStation: ChargingStation,