Added sites getOne/getMany/create routes
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"name": "Notifications",
"description": "Notifications API"
},
+ {
+ "name": "Sites",
+ "description": "Sites API"
+ },
{
"name": "OCPI",
"description": "OCPI API"

MODIFY
src/server/rest/v1/router/GlobalRouter.ts
src/server/rest/v1/router/GlobalRouter.ts
@@ -14,6 +14,7 @@ import OICPEndpointRouter from './api/OICPEndpointRouter';
import PricingRouter from './api/PricingRouter';
import RegistrationTokenRouter from './api/RegistrationTokenRouter';
import SettingRouter from './api/SettingRouter';
+import SiteRouter from './api/SiteRouter';
import SwaggerRouter from './doc/SwaggerRouter';
import TagRouter from './api/TagRouter';
import TenantRouter from './api/TenantRouter';
@@ -58,6 +59,7 @@ export default class GlobalRouter {
new OICPEndpointRouter().buildRoutes(),
new RegistrationTokenRouter().buildRoutes(),
new SettingRouter().buildRoutes(),
+ new SiteRouter().buildRoutes(),
new TagRouter().buildRoutes(),
new TenantRouter().buildRoutes(),
new TransactionRouter().buildRoutes(),

ADD
src/server/rest/v1/router/api/SiteRouter.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 SiteService from '../../service/SiteService';
+import sanitize from 'mongo-sanitize';
+
+export default class SiteRouter {
+ private router: express.Router;
+
+ public constructor() {
+ this.router = express.Router();
+ }
+
+ public buildRoutes(): express.Router {
+ this.buildRouteSites();
+ this.buildRouteSite();
+ this.buildRouteCreateSite();
+ return this.router;
+ }
+
+ private buildRouteSites(): void {
+ this.router.get(`/${ServerRoute.REST_SITES}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(SiteService.handleGetSites.bind(this), ServerAction.SITES, req, res, next);
+ });
+ }
+
+ private buildRouteSite(): void {
+ this.router.get(`/${ServerRoute.REST_SITE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = sanitize(req.params.id);
+ await RouterUtils.handleServerAction(SiteService.handleGetSite.bind(this), ServerAction.SITE, req, res, next);
+ });
+ }
+
+ private buildRouteCreateSite(): void {
+ this.router.post(`/${ServerRoute.REST_SITES}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(SiteService.handleCreateSite.bind(this), ServerAction.SITE_CREATE, req, res, next);
+ });
+ }
+}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -608,6 +608,9 @@ export enum ServerRoute {
REST_REGISTRATION_TOKENS = 'registration-tokens',
REST_REGISTRATION_TOKEN = 'registration-tokens/:id',
+ REST_SITES = 'sites',
+ REST_SITE = 'sites/: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',

MODIFY
test/api/client/SiteApi.ts
test/api/client/SiteApi.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 SiteApi extends CrudApi {
- public constructor(authenticatedApi) {
+ public constructor(authenticatedApi: AuthenticatedBaseApi) {
super(authenticatedApi);
}
- public async readById(id) {
- return super.readById(id, '/client/api/Site');
+ public async readById(id: string) {
+ return super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_SITE, { id }));
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, '/client/api/Sites');
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_SITES));
}
public async create(data) {
- const site = await super.create(data, '/client/api/SiteCreate');
+ const site = await super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_SITES));
// Check User IDs
if (data.userIDs) {
// Assign User IDs to Site

MODIFY
test/api/context/ContextProvider.ts
test/api/context/ContextProvider.ts
@@ -96,6 +96,8 @@ export default class ContextProvider {
if (tenantEntity.components && tenantEntity.components[TenantComponents.ORGANIZATION] &&
tenantEntity.components[TenantComponents.ORGANIZATION].active) {
siteAreaList = (await defaultAdminCentralServiceService.siteAreaApi.readAll({}, { limit: 0, skip: 0 })).data.result;
+ const asiteList = await defaultAdminCentralServiceService.siteApi.readAll({}, { limit: 0, skip: 0 });
+
siteList = (await defaultAdminCentralServiceService.siteApi.readAll({}, { limit: 0, skip: 0 })).data.result;
companyList = (await defaultAdminCentralServiceService.companyApi.readAll({}, { limit: 0, skip: 0 })).data.result;
chargingStationList = (await defaultAdminCentralServiceService.chargingStationApi.readAll({}, TestConstants.DEFAULT_PAGING)).data.result;

Added sites getOne/getMany/create routes