Added ocpi generate local token request type
MODIFY
src/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-by-id.json
src/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-by-id.json
"id": {
"$ref": "ocpi-endpoint.json#/definitions/id"
}
- }
+ },
+ "required": [
+ "id"
+ ]
}

MODIFY
src/server/rest/v1/service/OCPIEndpointService.ts
src/server/rest/v1/service/OCPIEndpointService.ts
@@ -838,17 +838,13 @@ export default class OCPIEndpointService {
});
}
// Filter
- const filteredRequest = OCPIEndpointValidator.getInstance().validateOCPIEndpointById(req.body);
- // Get OcpiEndpoint
- const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
- UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
- MODULE_NAME, 'handleGenerateLocalTokenOcpiEndpoint', req.user);
+ const filteredRequest = OCPIEndpointValidator.getInstance().validateOCPIEndpointGenerateLocalToken(req.body);
const tenant = await TenantStorage.getTenant(req.user.tenantID);
const localToken = OCPIUtils.generateLocalToken(tenant.subdomain);
await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleGenerateLocalTokenOcpiEndpoint',
- message: `Local Token for Ocpi Endpoint '${ocpiEndpoint.name}' has been generated successfully`,
+ message: `Local Token for Ocpi Endpoint '${filteredRequest.name}' has been generated successfully`,
action,
detailedMessages: { token: filteredRequest }
});

MODIFY
src/server/rest/v1/validator/OCPIEndpointValidator.ts
src/server/rest/v1/validator/OCPIEndpointValidator.ts
-import { HttpOCPIEndpointByIdRequest } from '../../../../types/requests/HttpOCPIEndpointRequest';
+import { HttpOCPIEndpointByIdRequest, HttpOCPIEndpointGenerateLocalTokenRequest } from '../../../../types/requests/HttpOCPIEndpointRequest';
+
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
@@ -10,6 +11,7 @@ export default class OCPIEndpointValidator extends SchemaValidator {
private ocpiEndpointCreate: Schema;
private ocpiEndpointPing: Schema;
private ocpiEndpointById: Schema;
+ private ocpiEndpointGenerateLocalToken: Schema;
private constructor() {
@@ -17,6 +19,7 @@ export default class OCPIEndpointValidator extends SchemaValidator {
this.ocpiEndpointCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-create.json`, 'utf8'));
this.ocpiEndpointPing = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-ping.json`, 'utf8'));
this.ocpiEndpointById = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-by-id.json`, 'utf8'));
+ this.ocpiEndpointGenerateLocalToken = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-generate-local-token.json`, 'utf8'));
}
public static getInstance(): OCPIEndpointValidator {
@@ -43,4 +46,10 @@ export default class OCPIEndpointValidator extends SchemaValidator {
this.validate(this.ocpiEndpointById, data);
return data;
}
+
+ public validateOCPIEndpointGenerateLocalToken(data: any): HttpOCPIEndpointGenerateLocalTokenRequest {
+ // Validate schema
+ this.validate(this.ocpiEndpointGenerateLocalToken, data);
+ return data;
+ }
}

MODIFY
src/types/requests/HttpOCPIEndpointRequest.ts
src/types/requests/HttpOCPIEndpointRequest.ts
@@ -8,3 +8,7 @@ export interface HttpOCPIEndpointsRequest extends HttpDatabaseRequest{
export interface HttpOCPIEndpointByIdRequest {
id: string;
}
+
+export interface HttpOCPIEndpointGenerateLocalTokenRequest extends HttpOCPIEndpointByIdRequest {
+ name: string;
+}

Added ocpi generate local token request type