Added company 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 CompanyRouter from './api/CompanyRouter';
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 CompanyRouter().buildRoutes(),
new TagRouter().buildRoutes(),
new TenantRouter().buildRoutes(),
new TransactionRouter().buildRoutes(),
new UserRouter().buildRoutes(),
- new BillingRouter().buildRoutes(),
]);
}

ADD
src/server/rest/v1/router/api/CompanyRouter.ts
+/* eslint-disable @typescript-eslint/no-misused-promises */
+import { ServerAction, ServerRoute } from '../../../../../types/Server';
+import express, { NextFunction, Request, Response } from 'express';
+
+import CompanyService from '../../service/CompanyService';
+import RouterUtils from '../RouterUtils';
+
+export default class CompanyRouter {
+ private router: express.Router;
+
+ public constructor() {
+ this.router = express.Router();
+ }
+
+ public buildRoutes(): express.Router {
+ this.buildRouteCompanies();
+ this.buildRouteCompany();
+ this.buildRouteCreateCompany();
+ this.buildRouteUpdateCompany();
+ this.buildRouteDeleteCompany();
+ this.buildRouteGetCompanyLogo();
+ return this.router;
+ }
+
+ protected buildRouteCompanies(): void {
+ this.router.get(`/${ServerRoute.REST_COMPANIES}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleGetCompanies.bind(this), ServerAction.COMPANIES, req, res, next);
+ });
+ }
+
+ protected buildRouteCompany(): void {
+ this.router.get(`/${ServerRoute.REST_COMPANY}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleGetCompany.bind(this), ServerAction.COMPANY, req, res, next);
+ });
+ }
+
+ protected buildRouteCreateCompany(): void {
+ this.router.post(`/${ServerRoute.REST_COMPANIES}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleCreateCompany.bind(this), ServerAction.COMPANY_CREATE, req, res, next);
+ });
+ }
+
+ protected buildRouteUpdateCompany(): void {
+ this.router.put(`/${ServerRoute.REST_COMPANY}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleUpdateCompany.bind(this), ServerAction.COMPANY_UPDATE, req, res, next);
+ });
+ }
+
+ protected buildRouteDeleteCompany(): void {
+ this.router.delete(`/${ServerRoute.REST_COMPANY}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleDeleteCompany.bind(this), ServerAction.COMPANY_DELETE, req, res, next);
+ });
+ }
+
+ protected buildRouteGetCompanyLogo(): void {
+ this.router.get(`/${ServerRoute.REST_COMPANY_LOGO}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(CompanyService.handleGetCompanyLogo.bind(this), ServerAction.COMPANY_LOGO, req, res, next);
+ });
+ }
+}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -523,6 +523,10 @@ export enum ServerRoute {
REST_TENANTS = 'tenants',
REST_TENANT = 'tenants/:id',
+ REST_COMPANIES = 'companies',
+ REST_COMPANY = 'companies/:id',
+ REST_COMPANY_LOGO = 'companies/:id/logo',
+
// 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 company router