Added connection router
MODIFY
src/server/rest/v1/router/GlobalRouter.ts
src/server/rest/v1/router/GlobalRouter.ts
@@ -5,6 +5,7 @@ import AuthRouter from './auth/AuthRouter';
import AuthService from '../service/AuthService';
import BillingRouter from './api/BillingRouter';
import ChargingStationRouter from './api/ChargingStationRouter';
+import ConnectionRouter from './api/ConnectionRouter';
import { StatusCodes } from 'http-status-codes';
import SwaggerRouter from './doc/SwaggerRouter';
import TagRouter from './api/TagRouter';
@@ -38,13 +39,14 @@ export default class GlobalRouter {
AuthService.authenticate(),
AuthService.checkSessionHash.bind(this),
[
- new ChargingStationRouter().buildRoutes(),
new AssetRouter().buildRoutes(),
+ new BillingRouter().buildRoutes(),
+ new ChargingStationRouter().buildRoutes(),
+ new ConnectionRouter().buildRoutes(),
new TagRouter().buildRoutes(),
new TenantRouter().buildRoutes(),
new TransactionRouter().buildRoutes(),
new UserRouter().buildRoutes(),
- new BillingRouter().buildRoutes(),
]);
}

ADD
src/server/rest/v1/router/api/ConnectionRouter.ts
+/* eslint-disable @typescript-eslint/no-misused-promises */
+import { ServerAction, ServerRoute } from '../../../../../types/Server';
+import express, { NextFunction, Request, Response } from 'express';
+
+import ConnectionService from '../../service/ConnectionService';
+import RouterUtils from '../RouterUtils';
+import sanitize from 'mongo-sanitize';
+
+export default class ConnectionRouter {
+ private router: express.Router;
+
+ public constructor() {
+ this.router = express.Router();
+ }
+
+ public buildRoutes(): express.Router {
+ this.buildRouteConnections();
+ this.buildRouteConnection();
+ this.buildRouteCreateConnection();
+ this.buildRouteDeleteConnection();
+ return this.router;
+ }
+
+ protected buildRouteConnections(): void {
+ this.router.get(`/${ServerRoute.REST_CONNECTIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(ConnectionService.handleGetConnections.bind(this), ServerAction.INTEGRATION_CONNECTIONS, req, res, next);
+ });
+ }
+
+ protected buildRouteConnection(): void {
+ this.router.get(`/${ServerRoute.REST_CONNECTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = sanitize(req.params.id);
+ await RouterUtils.handleServerAction(ConnectionService.handleGetConnection.bind(this), ServerAction.INTEGRATION_CONNECTION, req, res, next);
+ });
+ }
+
+ protected buildRouteCreateConnection(): void {
+ this.router.post(`/${ServerRoute.REST_CONNECTIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(ConnectionService.handleCreateConnection.bind(this), ServerAction.INTEGRATION_CONNECTION_CREATE, req, res, next);
+ });
+ }
+
+ protected buildRouteDeleteConnection(): void {
+ this.router.delete(`/${ServerRoute.REST_CONNECTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = sanitize(req.params.id);
+ await RouterUtils.handleServerAction(ConnectionService.handleDeleteConnection.bind(this), ServerAction.INTEGRATION_CONNECTION_DELETE, req, res, next);
+ });
+ }
+}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -523,6 +523,9 @@ export enum ServerRoute {
REST_TENANTS = 'tenants',
REST_TENANT = 'tenants/:id',
+ REST_CONNECTIONS = 'connections',
+ REST_CONNECTION = 'connection/:id',
+
// BILLING URLs for CRUD operations on PAYMENT METHODS
REST_BILLING_PAYMENT_METHODS = 'users/:userID/payment-methods',
REST_BILLING_PAYMENT_METHOD = 'users/:userID/payment-methods/:paymentMethodID',

Added connection router