X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20IncomingRequestService.ts;h=7e92a9ca6517e374d8de7ab88170cd04b1be8726;hb=1431af786f4d2728bad4132d505758144798516b;hp=08fa5d2ebb4381755d8b12fe7221c1d650bd7ee4;hpb=81533a206ec56709897f27edf1298e7c86d74c31;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 08fa5d2e..7e92a9ca 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from 'url'; import type { JSONSchemaType } from 'ajv'; +import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; import OCPPError from '../../../exception/OCPPError'; import type { JsonObject, JsonType } from '../../../types/JsonType'; import { @@ -18,7 +19,6 @@ import type { IncomingRequestHandler } from '../../../types/ocpp/Requests'; import logger from '../../../utils/Logger'; import type ChargingStation from '../../ChargingStation'; import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; -import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; const moduleName = 'OCPP20IncomingRequestService'; @@ -37,15 +37,9 @@ export default class OCPP20IncomingRequestService extends OCPPIncomingRequestSer this.jsonSchemas = new Map>([ [ OCPP20IncomingRequestCommand.CLEAR_CACHE, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json' + ), ], ]); this.validatePayload.bind(this); @@ -151,4 +145,13 @@ export default class OCPP20IncomingRequestService extends OCPPIncomingRequestSer ); return false; } + + private parseJsonSchemaFile(relativePath: string): JSONSchemaType { + return JSON.parse( + fs.readFileSync( + path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath), + 'utf8' + ) + ) as JSONSchemaType; + } }