Added tenants + tenant/:id
MODIFY
src/server/rest/CentralRestServer.ts
src/server/rest/CentralRestServer.ts
@@ -20,6 +20,7 @@ import http from 'http';
import sanitize from 'express-sanitizer';
import socketio from 'socket.io';
import socketioJwt from 'socketio-jwt';
+import { tenantRouter } from './router/TenantRouter';
const MODULE_NAME = 'CentralRestServer';
@@ -47,6 +48,8 @@ export default class CentralRestServer {
this.expressApplication.use(sanitize());
// Authentication
this.expressApplication.use(CentralRestServerAuthentication.initialize());
+ // Routers
+ this.expressApplication.use('/v1/api', CentralRestServerAuthentication.authenticate(), tenantRouter);
// Auth services
this.expressApplication.all('/client/auth/:action', CentralRestServerAuthentication.authService.bind(this));
// Secured API

ADD
src/server/rest/router/TenantRouter.ts
+import express, { NextFunction, Request, Response } from 'express';
+
+import { ServerAction } from '../../../types/Server';
+import TenantService from '../service/TenantService';
+
+export const tenantRouter = express.Router();
+
+// Define the home page route
+tenantRouter.get('/tenants', async (req: Request, res: Response, next: NextFunction) => {
+ try {
+ await TenantService.handleGetTenants(ServerAction.TENANTS, req, res, next);
+ next();
+ } catch (error) {
+ next(error);
+ }
+});
+
+// Define the about route
+tenantRouter.get('/tenants/:id', async (req: Request, res: Response, next: NextFunction) => {
+ try {
+ req.query.ID = req.params.id;
+ await TenantService.handleGetTenant(ServerAction.TENANT, req, res, next);
+ next();
+ } catch (error) {
+ next(error);
+ }
+});
+

Added tenants + tenant/:id