Switched tenant routes to REST API
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
- "/api/tenants/{tenantID}": {
+ "/api/tenants/{id}": {
"get": {
"description": "Retrieve a Tenant",
"security": [
],
"parameters": [
{
- "in": "path",
- "name": "tenantID",
- "description": "Tenant ID",
- "required": true,
- "schema": {
- "type": "string"
- }
+ "$ref": "#/components/parameters/tenantID"
},
{
"$ref": "#/components/parameters/ProjectFields"
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
},
],
"parameters": [
{
- "in": "path",
- "name": "tenantID",
- "description": "Tenant ID",
- "required": true,
+ "$ref": "#/components/parameters/tenantID"
+ }
+ ],
+ "tags": [
+ "Tenant"
+ ],
+ "responses": {
+ "200": {
+ "description": "Tenant has been successfully deleted"
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ },
+ "put": {
+ "description": "Update a Tenant",
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/tenantID"
+ }
+ ],
+ "tags": [
+ "Tenant"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
"schema": {
- "type": "string"
+ "$ref": "#/components/schemas/Tenant"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Return the found Tenant",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Tenant"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
}
}
+ },
+ "/api/tenants/{id}/logo": {
+ "get": {
+ "description": "Retrieve a Tenant logo",
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/tenantID"
+ }
],
"tags": [
"Tenant"
],
"responses": {
"200": {
- "description": "Tenant has been successfully deleted"
+ "description": "Return the Tenant logo"
},
"401": {
"$ref": "#/components/responses/UnauthorizedError"
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
"Tenant": {
"type": "object",
"required": [
- "id",
"name",
"email",
"subdomain"
"properties": {
"id": {
"type": "string",
- "example": "5be7fb271014d90008992347"
+ "example": "5be7fb271014d90008992347",
+ "readOnly": true
},
"name": {
"type": "string",
"schema": {
"type": "string"
}
+ },
+ "tenantID": {
+ "in": "path",
+ "name": "id",
+ "description": "Tenant ID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
}
}
}

MODIFY
src/assets/server/rest/v1/schemas/tenant/tenant-create.json
src/assets/server/rest/v1/schemas/tenant/tenant-create.json
"title": "Create one Tenant",
"type": "object",
"properties": {
- "id": {
- "$ref": "tenant#/definitions/id"
- },
"name": {
"$ref": "tenant#/definitions/name"
},

MODIFY
src/server/rest/v1/router/api/TenantRouter.ts
src/server/rest/v1/router/api/TenantRouter.ts
@@ -16,6 +16,10 @@ export default class TenantRouter {
public buildRoutes(): express.Router {
this.buildRouteTenants();
this.buildRouteTenant();
+ this.buildRouteCreateTenant();
+ this.buildRouteUpdateTenant();
+ this.buildRouteDeleteTenant();
+ this.buildRouteGetTenantLogo();
return this.router;
}
@@ -31,4 +35,31 @@ export default class TenantRouter {
await RouterUtils.handleServerAction(TenantService.handleGetTenant.bind(this), ServerAction.TENANT, req, res, next);
});
}
+
+ private buildRouteCreateTenant(): void {
+ this.router.post(`/${ServerRoute.REST_TENANTS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(TenantService.handleCreateTenant.bind(this), ServerAction.TENANT_CREATE, req, res, next);
+ });
+ }
+
+ private buildRouteUpdateTenant(): void {
+ this.router.put(`/${ServerRoute.REST_TENANT}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(TenantService.handleUpdateTenant.bind(this), ServerAction.TENANT_UPDATE, req, res, next);
+ });
+ }
+
+ private buildRouteDeleteTenant(): void {
+ this.router.delete(`/${ServerRoute.REST_TENANT}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(TenantService.handleDeleteTenant.bind(this), ServerAction.TENANT_DELETE, req, res, next);
+ });
+ }
+
+ private buildRouteGetTenantLogo(): void {
+ this.router.get(`/${ServerRoute.REST_TENANT_LOGO}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(TenantService.handleDeleteTenant.bind(this), ServerAction.TENANT_DELETE, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -562,6 +562,7 @@ export enum ServerRoute {
REST_TENANTS = 'tenants',
REST_TENANT = 'tenants/:id',
+ REST_TENANT_LOGO = 'tenant/:id/logo',
REST_COMPANIES = 'companies',
REST_COMPANY = 'companies/:id',

MODIFY
test/api/client/TenantApi.ts
test/api/client/TenantApi.ts
-import { ServerAction, ServerRoute } from '../../../src/types/Server';
-
+import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
+import BaseApi from './utils/BaseApi';
import CrudApi from './utils/CrudApi';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class TenantApi extends CrudApi {
- private _baseApi;
- public constructor(authenticatedApi, baseApi) {
+ private _baseApi: BaseApi;
+ public constructor(authenticatedApi: AuthenticatedBaseApi, baseApi: BaseApi) {
super(authenticatedApi);
// For call without auth
this._baseApi = baseApi;
@@ -20,19 +21,18 @@ export default class TenantApi extends CrudApi {
}
public async create(data) {
- return super.create(data, '/client/api/TenantCreate');
+ return super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_TENANTS));
}
public async update(data) {
- return super.update(data, '/client/api/TenantUpdate');
+ return super.update(data, this.buildRestEndpointUrl(ServerRoute.REST_TENANT, { id: data.id }));
}
public async delete(id) {
return await this._authenticatedApi.send({
method: 'DELETE',
- url: '/client/api/TenantDelete',
+ url: this.buildRestEndpointUrl(ServerRoute.REST_TENANT, { id }),
params: {
- ID: id,
forced: true
}
});

Switched tenant routes to REST API