Added RegistrationToken getMany/getOne/create endpoints + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
{
"name": "OCPI",
"description": "OCPI API"
+ },
+ {
+ "name": "Registration tokens",
+ "description": "Registration tokens API"
}
],
"paths": {
}
}
},
- "/api/assets/{id}/consumptions": {
- "post": {
- "security": [
- {
- "bearerAuth": []
- }
- ],
- "description": "Push latest asset consumption",
- "parameters": [
- {
- "$ref": "#/components/parameters/assetID"
- }
- ],
- "tags": [
- "Assets"
- ],
- "requestBody": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/AssetConsumption"
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Asset consumption created successfully",
- "content": {
- "application/json": {
- "example": {
- "consumption": "###",
- "status": "Success"
- }
- }
- }
- },
- "401": {
- "$ref": "#/components/responses/UnauthorizedError"
- },
- "403": {
- "$ref": "#/components/responses/ForbiddenError"
- },
- "500": {
- "$ref": "#/components/responses/BackendError"
- },
- "550": {
- "description": "Asset does not exist"
- }
- }
- }
- },
"/api/charging-profiles": {
"get": {
"security": [
}
}
}
+ },
+ "/api/registration-tokens": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve a list of Registration Tokens",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/SiteAreaID"
+ },
+ {
+ "$ref": "#/components/parameters/SiteIDs"
+ }
+ ],
+ "tags": [
+ "Registration tokens"
+ ],
+ "responses": {
+ "200": {
+ "description": "Return Registration Tokens list",
+ "content": {
+ "application/json": {
+ "example": {
+ "count": 1,
+ "result": [
+ {
+ "createdBy": {
+ "firstName": "###",
+ "name": "###"
+ },
+ "createdOn": "2021-11-08T14:39:10.363Z",
+ "description": "###",
+ "expirationDate": "2021-12-08T14:39:10.363Z",
+ "revocationDate": null,
+ "siteAreaID": null,
+ "id": "###"
+ }
+ ]
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ }
+ }
+ },
+ "post": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Create a registration token",
+ "tags": [
+ "Registration tokens"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/RegistrationToken"
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Registration token created successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "id": "###",
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ }
+ }
+ }
+ },
+ "/api/registration-tokens/{id}": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve a Registration Token",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/RegistrationTokenID"
+ }
+ ],
+ "tags": [
+ "Registration tokens"
+ ],
+ "responses": {
+ "200": {
+ "description": "Registration Token created successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "id": "###",
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ }
+ }
+ }
}
},
"components": {
"type": "boolean"
}
}
+ },
+ "RegistrationToken": {
+ "type": "object",
+ "required": [
+ "description"
+ ],
+ "properties": {
+ "id": {
+ "type": "string",
+ "readOnly": true
+ },
+ "description": {
+ "type": "string"
+ },
+ "siteAreaID": {
+ "type": "string"
+ },
+ "expirationDate": {
+ "type": "string",
+ "format": "date-time"
+ }
+ }
}
},
"parameters": {
"schema": {
"type": "string"
}
+ },
+ "RegistrationTokenID": {
+ "in": "path",
+ "name": "id",
+ "description": "Registration token ID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
}
}
}

MODIFY
src/server/rest/v1/router/GlobalRouter.ts
src/server/rest/v1/router/GlobalRouter.ts
@@ -10,6 +10,7 @@ import Logging from '../../../../utils/Logging';
import LoggingRouter from './api/LoggingRouter';
import NotificationRouter from './api/NotificationRouter';
import OCPIEndpointRouter from './api/OCPIEndpointRouter';
+import RegistrationTokenRouter from './api/RegistrationTokenRouter';
import SwaggerRouter from './doc/SwaggerRouter';
import TagRouter from './api/TagRouter';
import TenantRouter from './api/TenantRouter';
@@ -52,6 +53,7 @@ export default class GlobalRouter {
new LoggingRouter().buildRoutes(),
new NotificationRouter().buildRoutes(),
new OCPIEndpointRouter().buildRoutes(),
+ new RegistrationTokenRouter().buildRoutes(),
new TagRouter().buildRoutes(),
new TenantRouter().buildRoutes(),
new TransactionRouter().buildRoutes(),

ADD
src/server/rest/v1/router/api/RegistrationTokenRouter.ts
+/* eslint-disable @typescript-eslint/no-misused-promises */
+import { ServerAction, ServerRoute } from '../../../../../types/Server';
+import express, { NextFunction, Request, Response } from 'express';
+
+import RegistrationTokenService from '../../service/RegistrationTokenService';
+import RouterUtils from '../RouterUtils';
+import sanitize from 'mongo-sanitize';
+
+export default class RegistrationTokenRouter {
+ private router: express.Router;
+
+ public constructor() {
+ this.router = express.Router();
+ }
+
+ public buildRoutes(): express.Router {
+ this.buildRouteRegistrationTokens();
+ this.buildRouteRegistrationToken();
+ this.buildRouteCreateRegistrationTokens();
+ return this.router;
+ }
+
+ protected buildRouteRegistrationTokens(): void {
+ this.router.get(`/${ServerRoute.REST_REGISTRATION_TOKENS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(RegistrationTokenService.handleGetRegistrationTokens.bind(this), ServerAction.REGISTRATION_TOKENS, req, res, next);
+ });
+ }
+
+ protected buildRouteRegistrationToken(): void {
+ this.router.get(`/${ServerRoute.REST_REGISTRATION_TOKEN}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = sanitize(req.params.id);
+ await RouterUtils.handleServerAction(RegistrationTokenService.handleGetRegistrationToken.bind(this), ServerAction.REGISTRATION_TOKEN, req, res, next);
+ });
+ }
+
+ protected buildRouteCreateRegistrationTokens(): void {
+ this.router.post(`/${ServerRoute.REST_REGISTRATION_TOKENS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(RegistrationTokenService.handleCreateRegistrationToken.bind(this), ServerAction.REGISTRATION_TOKEN_CREATE, req, res, next);
+ });
+ }
+}

DELETE
src/server/rest/v1/router/api/RegistrationTokensRouter.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 TenantService from '../../service/TenantService';
-import sanitize from 'mongo-sanitize';
-
-export default class TenantRouter {
- private router: express.Router;
-
- public constructor() {
- this.router = express.Router();
- }
-
- public buildRoutes(): express.Router {
- this.buildRouteTenants();
- this.buildRouteTenant();
- return this.router;
- }
-
- protected buildRouteTenants(): void {
- this.router.get(`/${ServerRoute.REST_TENANTS}`, async (req: Request, res: Response, next: NextFunction) => {
- await RouterUtils.handleServerAction(TenantService.handleGetTenants.bind(this), ServerAction.TENANTS, req, res, next);
- });
- }
-
- protected buildRouteTenant(): void {
- this.router.get(`/${ServerRoute.REST_TENANT}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = sanitize(req.params.id);
- await RouterUtils.handleServerAction(TenantService.handleGetTenant.bind(this), ServerAction.TENANT, req, res, next);
- });
- }
-}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -586,6 +586,9 @@ export enum ServerRoute {
REST_OCPI_ENDPOINT_REGISTER = 'ocpi/endpoints/:id/register',
REST_OCPI_ENDPOINT_UNREGISTER = 'ocpi/endpoints/:id/unregister',
+ REST_REGISTRATION_TOKENS = 'registration-tokens',
+ REST_REGISTRATION_TOKEN = 'registration-tokens/: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/RegistrationTokenApi.ts
test/api/client/RegistrationTokenApi.ts
+import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
import CrudApi from './utils/CrudApi';
+import RegistrationToken from '../../../src/types/RegistrationToken';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class RegistrationTokenApi extends CrudApi {
- public constructor(authenticatedApi) {
+ public constructor(authenticatedApi: AuthenticatedBaseApi) {
super(authenticatedApi);
}
public async readById(id) {
- return await super.readById(id, '/client/api/RegistrationToken');
+ return await super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_REGISTRATION_TOKEN, { id }));
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return await super.readAll(params, paging, ordering, '/client/api/RegistrationTokens');
+ return await super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_REGISTRATION_TOKENS));
}
- public async create(data = {}) {
- return await super.create(data, '/client/api/RegistrationTokenCreate');
+ public async create(data: Partial<RegistrationToken>) {
+ return await super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_REGISTRATION_TOKENS));
}
public async update(data) {

Added RegistrationToken getMany/getOne/create endpoints + doc