Added OCPIEndpoints getMany/getOne/update/register endpoints
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
},
"/api/ocpi/endpoints": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve a list of OCPI Endpoints",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/Search"
+ },
+ {
+ "$ref": "#/components/parameters/Skip"
+ },
+ {
+ "$ref": "#/components/parameters/SortFields"
+ },
+ {
+ "$ref": "#/components/parameters/Limit"
+ },
+ {
+ "$ref": "#/components/parameters/OnlyRecordCount"
+ },
+ {
+ "$ref": "#/components/parameters/ProjectFields"
+ }
+ ],
+ "tags": [
+ "OCPI"
+ ],
+ "responses": {
+ "200": {
+ "description": "Return OCPI Endpoints list",
+ "content": {
+ "application/json": {
+ "example": {
+ "count": 1,
+ "result": [
+ {
+ "name": "###",
+ "baseUrl": "###",
+ "localToken": "###",
+ "token": "###",
+ "countryCode": "##",
+ "partyId": "###",
+ "backgroundPatchJob": true,
+ "status": "###",
+ "version": "2.1.1",
+ "lastPatchJobOn": "2021-03-05T22:35:03.857Z",
+ "lastPatchJobResult": {
+ "successNbr": 0,
+ "failureNbr": 0,
+ "totalNbr": 12
+ },
+ "lastChangedOn": "2020-11-07T22:36:50.094Z",
+ "role": "###",
+ "id": "###"
+ }
+ ]
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ }
+ }
+ },
"post": {
"security": [
{
}
}
},
+ "/api/ocpi/endpoints/{id}": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve an OCPI Endpoints",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/OCPIEndpointID"
+ }
+ ],
+ "tags": [
+ "OCPI"
+ ],
+ "responses": {
+ "200": {
+ "description": "Return OCPI Endpoint",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/OCPIEndpoint"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ },
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Update an OCPI Endpoint",
+ "tags": [
+ "OCPI"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/OCPIEndpoint"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "OCPI Endpoint updated successfully",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
"/api/ocpi/endpoints/{id}/ping": {
"put": {
"security": [
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}
},
"500": {
"$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
+ "/api/ocpi/endpoints/:id/register": {
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Register OCPI Endpoint",
+ "tags": [
+ "OCPI"
+ ],
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/OCPIEndpointID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/OCPIEndpoint"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "OCPI Endpoint's local tokens generated",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success",
+ "statusCode": 200,
+ "statusText": "OK"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
}
}
}

MODIFY
src/server/rest/v1/router/api/OCPIRouter.ts
src/server/rest/v1/router/api/OCPIRouter.ts
@@ -25,6 +25,10 @@ export default class OCPIRouter {
this.buildRouteOcpiEndpointSendEVSEStatuses();
this.buildRouteOcpiEndpointSendTokens();
this.buildRouteOcpiEndpointGenerateTokens();
+ this.buildRouteOcpiEndpoints();
+ this.buildRouteOcpiEndpoint();
+ this.buildRouteOcpiEndpointUpdate();
+ this.buildRouteOcpiEndpointRegister();
return this.router;
}
@@ -36,67 +40,105 @@ export default class OCPIRouter {
protected buildRouteOcpiEndpointPing(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_PING}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePingOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_PING, req, res, next);
});
}
protected buildRouteOcpiEndpointCheckCDRs(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_CHECK_CDRS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handleCheckCdrsEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_CHECK_CDRS, req, res, next);
});
}
protected buildRouteOcpiEndpointCheckLocations(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_CHECK_LOCATIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handleCheckLocationsEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_CHECK_LOCATIONS, req, res, next);
});
}
protected buildRouteOcpiEndpointCheckSessions(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_CHECK_SESSIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handleCheckSessionsEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_CHECK_SESSIONS, req, res, next);
});
}
protected buildRouteOcpiEndpointPullCDRs(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_PULL_CDRS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePullCdrsEndpoint.bind(this), ServerAction.OCPI_PULL_CDRS, req, res, next);
});
}
protected buildRouteOcpiEndpointPullLocations(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_PULL_LOCATIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePullLocationsEndpoint.bind(this), ServerAction.OCPI_PULL_LOCATIONS, req, res, next);
});
}
protected buildRouteOcpiEndpointPullSessions(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_PULL_SESSIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePullSessionsEndpoint.bind(this), ServerAction.OCPI_PULL_SESSIONS, req, res, next);
});
}
protected buildRouteOcpiEndpointPullTokens(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_PULL_TOKENS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePullTokensEndpoint.bind(this), ServerAction.OCPI_PULL_TOKENS, req, res, next);
});
}
protected buildRouteOcpiEndpointSendEVSEStatuses(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_SEND_EVSE_STATUSES}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePushEVSEStatusesOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_SEND_EVSE_STATUSES, req, res, next);
});
}
protected buildRouteOcpiEndpointSendTokens(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_SEND_TOKENS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handlePushTokensOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_SEND_TOKENS, req, res, next);
});
}
protected buildRouteOcpiEndpointGenerateTokens(): void {
this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_GENERATE_LOCAL_TOKEN}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(OCPIEndpointService.handleGenerateLocalTokenOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_GENERATE_LOCAL_TOKEN, req, res, next);
});
}
+
+ protected buildRouteOcpiEndpoints(): void {
+ this.router.get(`/${ServerRoute.REST_OCPI_ENDPOINTS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(OCPIEndpointService.handleGetOcpiEndpoints.bind(this), ServerAction.OCPI_ENDPOINTS, req, res, next);
+ });
+ }
+
+ protected buildRouteOcpiEndpoint(): void {
+ this.router.get(`/${ServerRoute.REST_OCPI_ENDPOINT}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(OCPIEndpointService.handleGetOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT, req, res, next);
+ });
+ }
+
+ protected buildRouteOcpiEndpointUpdate(): void {
+ this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(OCPIEndpointService.handleUpdateOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_UPDATE, req, res, next);
+ });
+ }
+
+ protected buildRouteOcpiEndpointRegister(): void {
+ this.router.put(`/${ServerRoute.REST_OCPI_ENDPOINT_REGISTER}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.body.id = req.params.id;
+ await RouterUtils.handleServerAction(OCPIEndpointService.handleRegisterOcpiEndpoint.bind(this), ServerAction.OCPI_ENDPOINT_REGISTER, req, res, next);
+ });
+ }
}

MODIFY
test/api/OCPIEndpointTest.ts
test/api/OCPIEndpointTest.ts
@@ -4,6 +4,7 @@ import CentralServerService from './client/CentralServerService';
import ContextDefinition from './context/ContextDefinition';
import ContextProvider from './context/ContextProvider';
import Factory from '../factories/Factory';
+import OCPIEndpoint from '../../src/types/ocpi/OCPIEndpoint';
import TenantContext from './context/TenantContext';
import User from '../../src/types/User';
import chaiSubset from 'chai-subset';
@@ -15,7 +16,7 @@ class TestData {
public tenantContext: TenantContext;
public centralUserContext: any;
public userContext: User;
- public newOcpiEndpoint: any;
+ public newOcpiEndpoint: OCPIEndpoint;
}
const testData: TestData = new TestData();

MODIFY
test/api/client/OCPIEndpointApi.ts
test/api/client/OCPIEndpointApi.ts
import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
import CrudApi from './utils/CrudApi';
+import OCPIEndpoint from '../../../src/types/ocpi/OCPIEndpoint';
import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
@@ -9,19 +10,19 @@ export default class OCPIEndpointApi extends CrudApi {
}
public async readById(id) {
- return super.readById(id, '/client/api/OcpiEndpoint');
+ return super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_OCPI_ENDPOINT, { id }));
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, '/client/api/OcpiEndpoints');
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_OCPI_ENDPOINTS));
}
- public async create(data) {
+ public async create(data: OCPIEndpoint) {
return super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_OCPI_ENDPOINT_CREATE));
}
- public async update(data) {
- return super.update(data, '/client/api/OcpiEndpointUpdate');
+ public async update(data: OCPIEndpoint) {
+ return super.update(data, this.buildRestEndpointUrl(ServerRoute.REST_OCPI_ENDPOINT, { id: data.id }));
}
public async delete(id) {

Added OCPIEndpoints getMany/getOne/update/register endpoints