refactor: rename src/charging-station/Utils.ts -> src/charging-station/Helpers.ts
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIHttpServer.ts
index 32b82e9c995a45c22fb8d1828c5bb16215056314..e11fd4bdc662e18597887dca4c5273578a6f6724 100644 (file)
@@ -6,6 +6,7 @@ import { AbstractUIServer } from './AbstractUIServer';
 import { UIServerUtils } from './UIServerUtils';
 import { BaseError } from '../../exception';
 import {
+  ApplicationProtocolVersion,
   type ProcedureName,
   type Protocol,
   type ProtocolRequest,
@@ -43,9 +44,12 @@ export class UIHttpServer extends AbstractUIServer {
     this.startHttpServer();
   }
 
-  // eslint-disable-next-line @typescript-eslint/no-unused-vars
   public sendRequest(request: ProtocolRequest): void {
-    // This is intentionally left blank
+    switch (this.uiServerConfiguration.version) {
+      case ApplicationProtocolVersion.VERSION_20:
+        this.httpServer.emit('request', request);
+        break;
+    }
   }
 
   public sendResponse(response: ProtocolResponse): void {
@@ -116,9 +120,9 @@ export class UIHttpServer extends AbstractUIServer {
         );
       });
       if (req.method === HttpMethods.POST) {
-        const bodyBuffer = [];
+        const bodyBuffer: Uint8Array[] = [];
         req
-          .on('data', (chunk) => {
+          .on('data', (chunk: Uint8Array) => {
             bodyBuffer.push(chunk);
           })
           .on('end', () => {
@@ -132,9 +136,9 @@ export class UIHttpServer extends AbstractUIServer {
                   body ?? Constants.EMPTY_FREEZED_OBJECT,
                 ),
               )
-              .then((protocolResponse: ProtocolResponse) => {
+              .then((protocolResponse?: ProtocolResponse) => {
                 if (!isNullOrUndefined(protocolResponse)) {
-                  this.sendResponse(protocolResponse);
+                  this.sendResponse(protocolResponse!);
                 }
               })
               .catch(Constants.EMPTY_FUNCTION);