Fixed OCPI typos / logs
MODIFY
src/server/ocpi/OCPIUtils.ts
src/server/ocpi/OCPIUtils.ts
@@ -54,9 +54,9 @@ export default class OCPIUtils {
// Get ocpi service configuration
const ocpiSetting = await SettingStorage.getOCPISettings(tenant);
// Define version url
- credential.url = (versionUrl ? versionUrl : `${Configuration.getOCPIEndpointConfig().baseUrl}/ocpi/${role.toLowerCase()}/versions`);
+ credential.url = versionUrl ?? `${Configuration.getOCPIEndpointConfig().baseUrl}/ocpi/${role.toLowerCase()}/versions`;
// Check if available
- if (ocpiSetting && ocpiSetting.ocpi) {
+ if (ocpiSetting?.ocpi) {
credential.token = token;
if (role === OCPIRole.EMSP) {
credential.country_code = ocpiSetting.ocpi.emsp.countryCode;

MODIFY
src/server/ocpi/router/common/V2.1.1/CPOEMSPCredentialsRouterV211.ts
src/server/ocpi/router/common/V2.1.1/CPOEMSPCredentialsRouterV211.ts
@@ -21,13 +21,13 @@ export default class CPOEMSPCredentialsRouterV211 {
protected buildRouteCreateCredentials(): void {
this.router.post(`/${OCPIServerRoute.OCPI_CREDENTIALS}`, async (req: Request, res: Response, next: NextFunction) => {
- await RouterUtils.handleOCPIServerAction(CPOEMSPCredentialsService.handleCreateCredentials.bind(this), ServerAction.OCPI_CREATE_CREDENTIALS, req, res, next);
+ await RouterUtils.handleOCPIServerAction(CPOEMSPCredentialsService.handleUpdateCreateCredentials.bind(this), ServerAction.OCPI_CREATE_CREDENTIALS, req, res, next);
});
}
protected buildRouteUpdateCredentials(): void {
this.router.put(`/${OCPIServerRoute.OCPI_CREDENTIALS}`, async (req: Request, res: Response, next: NextFunction) => {
- await RouterUtils.handleOCPIServerAction(CPOEMSPCredentialsService.handleCreateCredentials.bind(this), ServerAction.OCPI_CREATE_CREDENTIALS, req, res, next);
+ await RouterUtils.handleOCPIServerAction(CPOEMSPCredentialsService.handleUpdateCreateCredentials.bind(this), ServerAction.OCPI_UPDATE_CREDENTIALS, req, res, next);
});
}

MODIFY
src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts
src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts
@@ -48,21 +48,20 @@ export default class CPOEMSPCredentialsService {
next();
}
- public static async handleCreateCredentials(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleUpdateCreateCredentials(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
const { tenant, ocpiEndpoint } = req;
// Get payload
- const credential: OCPICredential = req.body;
- // Log body
+ const credential = req.body as OCPICredential;
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Received credential object',
detailedMessages: { credential }
});
// Check if valid
if (!CPOEMSPCredentialsService.isValidOCPICredential(credential)) {
throw new AppError({
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
errorCode: HTTPError.GENERAL_ERROR,
message: 'Invalid Credential Object',
ocpiError: OCPIStatusCode.CODE_2000_GENERIC_CLIENT_ERROR
@@ -76,7 +75,7 @@ export default class CPOEMSPCredentialsService {
// Log body
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Received token',
detailedMessages: { token }
});
@@ -89,7 +88,7 @@ export default class CPOEMSPCredentialsService {
// Log updated ocpi endpoint
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'OCPI Server found and updated with credential object',
detailedMessages: { ocpiEndpoint }
});
@@ -105,14 +104,14 @@ export default class CPOEMSPCredentialsService {
// Log available OCPI Versions
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Available OCPI Versions',
detailedMessages: { versions: response.data }
});
// Check response
if (!response.data || !response.data.data) {
throw new BackendError({
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: `Invalid response from GET ${ocpiEndpoint.baseUrl}`,
detailedMessages: { data: response.data }
});
@@ -127,7 +126,7 @@ export default class CPOEMSPCredentialsService {
// Log correct OCPI service found
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Correct OCPI version found',
detailedMessages: `[${ocpiEndpoint.version}]:${ocpiEndpoint.versionUrl}`
});
@@ -136,7 +135,7 @@ export default class CPOEMSPCredentialsService {
// If not found trigger exception
if (!versionFound) {
throw new BackendError({
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'OCPI Endpoint version 2.1.1 not found',
detailedMessages: { data: response.data }
});
@@ -150,14 +149,14 @@ export default class CPOEMSPCredentialsService {
// Log available OCPI services
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Available OCPI services',
detailedMessages: { endpoints: response.data }
});
// Check response
- if (!response.data || !response.data.data) {
+ if (!response.data?.data) {
throw new BackendError({
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: `Invalid response from GET ${ocpiEndpoint.versionUrl}`,
detailedMessages: { data: response.data }
});
@@ -166,7 +165,7 @@ export default class CPOEMSPCredentialsService {
ocpiEndpoint.availableEndpoints = OCPIUtils.convertAvailableEndpoints(response.data.data);
} catch (error) {
throw new AppError({
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
errorCode: HTTPError.GENERAL_ERROR,
message: `Unable to use client API: ${error.message as string}`,
ocpiError: OCPIStatusCode.CODE_3001_UNABLE_TO_USE_CLIENT_API_ERROR,
@@ -185,7 +184,7 @@ export default class CPOEMSPCredentialsService {
// Log available OCPI Versions
await Logging.logDebug({
tenantID: tenant.id,
- module: MODULE_NAME, method: 'handleCreateCredentials', action,
+ module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action,
message: 'Response with credential object',
detailedMessages: { respCredential }
});

Fixed OCPI typos / logs