Fixed OCPI token status
MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -360,16 +360,7 @@ export default class EmspOCPIClient extends OCPIClient {
detailedMessages: { user: tag.user }
});
}
- const token: OCPIToken = {
- uid: tag.id,
- type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
- auth_id: tag.user.id,
- visual_number: tag.visualID,
- issuer: this.tenant.name,
- valid: true,
- whitelist: OCPITokenWhitelist.ALLOWED_OFFLINE,
- last_updated: new Date()
- };
+ const token = OCPIUtils.buildOCPITokenFromTag(this.tenant, tag);
const authorizationId = Utils.generateUUID();
// Get the location ID from the Site Area name
const locationID = chargingStation.ocpiData.evses[0].location_id;

MODIFY
src/server/ocpi/OCPIUtils.ts
src/server/ocpi/OCPIUtils.ts
@@ -3,7 +3,7 @@ import { OCPIConnector, OCPIConnectorType } from '../../types/ocpi/OCPIConnector
import OCPIEndpoint, { OCPIAvailableEndpoints, OCPIEndpointVersions } from '../../types/ocpi/OCPIEndpoint';
import { OCPIEvse, OCPIEvseStatus } from '../../types/ocpi/OCPIEvse';
import { OCPITariff, OCPITariffDimensionType } from '../../types/ocpi/OCPITariff';
-import { OCPIToken, OCPITokenType } from '../../types/ocpi/OCPIToken';
+import { OCPIToken, OCPITokenType, OCPITokenWhitelist } from '../../types/ocpi/OCPIToken';
import AppError from '../../exception/AppError';
import BackendError from '../../exception/BackendError';
@@ -30,7 +30,9 @@ import Site from '../../types/Site';
import SiteArea from '../../types/SiteArea';
import SiteAreaStorage from '../../storage/mongodb/SiteAreaStorage';
import SiteStorage from '../../storage/mongodb/SiteStorage';
+import Tag from '../../types/Tag';
import Tenant from '../../types/Tenant';
+import { UserStatus } from '../../types/User';
import Utils from '../../utils/Utils';
import moment from 'moment';
@@ -165,6 +167,19 @@ export default class OCPIUtils {
return tagID.length % 8 === 0 ? OCPITokenType.RFID : OCPITokenType.OTHER;
}
+ public static buildOCPITokenFromTag(tenant: Tenant, tag: Tag): OCPIToken {
+ return {
+ uid: tag.id,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
+ auth_id: tag.id,
+ visual_number: tag.visualID,
+ issuer: tenant.name,
+ valid: tag.active && tag.user?.status === UserStatus.ACTIVE,
+ whitelist: OCPITokenWhitelist.ALLOWED_OFFLINE,
+ last_updated: tag.lastChangedOn ?? new Date()
+ };
+ }
+
public static generateLocalToken(tenantSubdomain: string): string {
const newToken: any = {};
// Generate random

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -88,19 +88,12 @@ export default class OCPIUtilsService {
const tags = await TagStorage.getTags(tenant,
{ issuer: true, dateFrom, dateTo, withUsersOnly: true, withUser: true },
{ limit, skip },
- [ 'id', 'userID', 'user.deleted', 'lastChangedOn' ]);
+ [ 'id', 'visualID', 'active', 'userID', 'user.status', 'user.deleted', 'lastChangedOn' ]);
// Convert Sites to Locations
for (const tag of tags.result) {
- tokens.push({
- uid: tag.id,
- type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
- auth_id: tag.id,
- visual_number: tag.visualID,
- issuer: tenant.name,
- valid: !Utils.isNullOrUndefined(tag.user),
- whitelist: OCPITokenWhitelist.ALLOWED_OFFLINE,
- last_updated: tag.lastChangedOn ? tag.lastChangedOn : new Date()
- });
+ // Create Token
+ const ocpiToken = OCPIUtils.buildOCPITokenFromTag(tenant, tag);
+ tokens.push(ocpiToken);
}
let nbrOfTags = tags.count;
if (nbrOfTags === -1) {

Fixed OCPI token status