Check the OCPI Tag's status
MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/emsp/EMSPTokensEndpoint.ts
@@ -116,35 +116,43 @@ export default class EMSPTokensEndpoint extends AbstractEndpoint {
});
}
const tag = await TagStorage.getTag(tenant, tokenID, { withUser: true });
- if (!tag?.user) {
+ if (!tag) {
throw new AppError({
action: ServerAction.OCPI_AUTHORIZE_TOKEN,
module: MODULE_NAME, method: 'authorizeRequest',
errorCode: HTTPError.GENERAL_ERROR,
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR,
- message: `Unkwnown User for OCPI Token ID '${tokenID}'`,
+ message: `Unkwnown Tag ID '${tokenID}'`,
detailedMessages: { tokenID, location }
});
}
- let allowedStatus: OCPIAllowed;
- if (!tag.issuer) {
- allowedStatus = OCPIAllowed.NOT_ALLOWED;
- } else {
- switch (tag.user.status) {
- case UserStatus.ACTIVE:
- allowedStatus = OCPIAllowed.ALLOWED;
- break;
- case UserStatus.BLOCKED:
- allowedStatus = OCPIAllowed.BLOCKED;
- break;
- default:
- allowedStatus = OCPIAllowed.NOT_ALLOWED;
+ // Check Tag
+ if (!tag.issuer || !tag.active) {
+ return OCPIUtils.success({
+ allowed: OCPIAllowed.NOT_ALLOWED,
+ authorization_id: Utils.generateUUID(), location
+ });
}
+ // Check User
+ if (!tag.user) {
+ throw new AppError({
+ action: ServerAction.OCPI_AUTHORIZE_TOKEN,
+ module: MODULE_NAME, method: 'authorizeRequest',
+ errorCode: HTTPError.GENERAL_ERROR,
+ ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR,
+ message: `Unkwnown User for OCPI Token ID '${tokenID}'`,
+ detailedMessages: { tokenID, location, tag }
+ });
+ }
+ if (tag.user.status !== UserStatus.ACTIVE) {
+ return OCPIUtils.success({
+ allowed: tag.user.status === UserStatus.BLOCKED ? OCPIAllowed.BLOCKED : OCPIAllowed.NOT_ALLOWED,
+ authorization_id: Utils.generateUUID(), location
+ });
}
return OCPIUtils.success({
- allowed: allowedStatus,
- authorization_id: Utils.generateUUID(),
- location: location
+ allowed: OCPIAllowed.ALLOWED,
+ authorization_id: Utils.generateUUID(), location
});
}
}

Check the OCPI Tag's status