Refine TS and linter configuration
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / AbstractUIService.ts
index e27577d353e004491a7e926facc24cce4efa41d4..e72af5c0549fa1feb2f4c9bfd66225f53fe76e27 100644 (file)
@@ -1,13 +1,12 @@
-import { RawData } from 'ws';
+import type { RawData } from 'ws';
 
 import BaseError from '../../../exception/BaseError';
 import { Bootstrap } from '../../../internal';
-import { JsonType } from '../../../types/JsonType';
+import type { JsonType } from '../../../types/JsonType';
 import {
   ProcedureName,
   ProtocolRequest,
   ProtocolRequestHandler,
-  ProtocolResponse,
   ProtocolVersion,
   RequestPayload,
   ResponsePayload,
@@ -80,31 +79,20 @@ export default abstract class AbstractUIService {
     procedureName: ProcedureName,
     requestPayload: RequestPayload
   ): void {
-    this.uiServer.sendRequest(this.buildProtocolRequest(messageId, procedureName, requestPayload));
+    this.uiServer.sendRequest(
+      this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload)
+    );
   }
 
   public sendResponse(messageId: string, responsePayload: ResponsePayload): void {
-    this.uiServer.sendResponse(this.buildProtocolResponse(messageId, responsePayload));
+    this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));
   }
 
   public logPrefix(modName: string, methodName: string): string {
     return this.uiServer.logPrefix(modName, methodName);
   }
 
-  private buildProtocolRequest(
-    messageId: string,
-    procedureName: ProcedureName,
-    requestPayload: RequestPayload
-  ): string {
-    return JSON.stringify([messageId, procedureName, requestPayload] as ProtocolRequest);
-  }
-
-  private buildProtocolResponse(messageId: string, responsePayload: ResponsePayload): string {
-    return JSON.stringify([messageId, responsePayload] as ProtocolResponse);
-  }
-
-  // Validate the raw data received from the WebSocket
-  // TODO: should probably be moved to the ws verify clients callback
+  // Validate the raw data received from the UI server
   private requestValidation(rawData: RawData | JsonType): ProtocolRequest {
     // logger.debug(
     //   `${this.logPrefix(