Added site-area 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 SiteAreaRouter from './api/SiteAreaRouter';
import { StatusCodes } from 'http-status-codes';
import SwaggerRouter from './doc/SwaggerRouter';
import TagRouter from './api/TagRouter';
@@ -40,6 +41,7 @@ export default class GlobalRouter {
[
new ChargingStationRouter().buildRoutes(),
new AssetRouter().buildRoutes(),
+ new SiteAreaRouter().buildRoutes(),
new TagRouter().buildRoutes(),
new TenantRouter().buildRoutes(),
new TransactionRouter().buildRoutes(),

ADD
src/server/rest/v1/router/api/SiteAreaRouter.ts
+/* eslint-disable @typescript-eslint/no-misused-promises */
+import { ServerAction, ServerRoute } from '../../../../../types/Server';
+import express, { NextFunction, Request, Response } from 'express';
+
+import RouterUtils from '../RouterUtils';
+import SiteAreaService from '../../service/SiteAreaService';
+
+export default class SiteAreaRouter {
+ private router: express.Router;
+
+ public constructor() {
+ this.router = express.Router();
+ }
+
+ public buildRoutes(): express.Router {
+ this.buildRouteSiteAreas();
+ this.buildRouteSiteArea();
+ this.buildRouteCreateSiteArea();
+ return this.router;
+ }
+
+ protected buildRouteSiteAreas(): void {
+ this.router.get(`/${ServerRoute.REST_SITE_AREAS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(SiteAreaService.handleGetSiteAreas.bind(this), ServerAction.SITE_AREAS, req, res, next);
+ });
+ }
+
+ protected buildRouteSiteArea(): void {
+ this.router.get(`/${ServerRoute.REST_SITE_AREA}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(SiteAreaService.handleGetSiteArea.bind(this), ServerAction.SITE_AREA, req, res, next);
+ });
+ }
+
+ protected buildRouteCreateSiteArea(): void {
+ this.router.post(`/${ServerRoute.REST_SITE_AREAS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(SiteAreaService.handleCreateSiteArea.bind(this), ServerAction.SITE_AREA_CREATE, req, res, next);
+ });
+ }
+}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -523,6 +523,11 @@ export enum ServerRoute {
REST_TENANTS = 'tenants',
REST_TENANT = 'tenants/:id',
+ REST_SITE_AREAS = 'site-areas',
+ REST_SITE_AREA = 'site-areas/:id',
+ REST_SITE_AREA_CONSUMPTION = 'site-areas/:id/consumptions',
+ REST_SITE_AREA_IMAGE = 'site-areas/:id/image',
+
// 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',

MODIFY
test/api/client/SiteAreaApi.ts
test/api/client/SiteAreaApi.ts
+import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
import CrudApi from './utils/CrudApi';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class SiteAreaApi extends CrudApi {
- public constructor(authenticatedApi) {
+ public constructor(authenticatedApi: AuthenticatedBaseApi) {
super(authenticatedApi);
}
public async readById(id) {
- return super.readById(id, '/client/api/SiteArea');
+ return super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_SITE_AREA, { id }));
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, '/client/api/SiteAreas');
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_SITE_AREAS));
}
public async create(data) {
- const siteArea = await super.create(data, '/client/api/SiteAreaCreate');
+ const siteArea = await super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_SITE_AREAS));
// Check User IDs
if (data.chargeBoxIDs) {
// Assign Chargers to Site

Added site-area router