Fixed eMSP push of local tag without user not working. Add index in tags. Handle virtual badges as no RFID tags. Limit number of fields returned by the TagStorage.
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -99,7 +99,8 @@ export default class CpoOCPIClient extends OCPIClient {
for (const token of response.data.data as OCPIToken[]) {
tagIDs.push(token.uid);
}
- const tags = (await TagStorage.getTags(this.tenant.id, { tagIDs: tagIDs }, Constants.DB_PARAMS_MAX_LIMIT)).result;
+ const tags = await TagStorage.getTags(this.tenant.id,
+ { tagIDs: tagIDs }, Constants.DB_PARAMS_MAX_LIMIT);
for (const token of response.data.data as OCPIToken[]) {
try {
// Get eMSP user
@@ -114,7 +115,7 @@ export default class CpoOCPIClient extends OCPIClient {
}
}
// Get the Tag
- const emspTag = tags.find((tag) => tag.id === token.uid);
+ const emspTag = tags.result.find((tag) => tag.id === token.uid);
await OCPIUtilsService.updateToken(this.tenant.id, this.ocpiEndpoint, token, emspTag, emspUser);
result.success++;
} catch (error) {

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -299,13 +299,6 @@ export default class EmspOCPIClient extends OCPIClient {
}
public async processLocation(location: OCPILocation, company: Company, sites: Site[]): Promise<void> {
- Logging.logDebug({
- tenantID: this.tenant.id,
- action: ServerAction.OCPI_PULL_LOCATIONS,
- message: `Processing Location '${location.name}' with ID '${location.id}'`,
- module: MODULE_NAME, method: 'processLocation',
- detailedMessages: location
- });
// Handle Site
let site: Site;
const siteName = location.operator && location.operator.name ? location.operator.name

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
@@ -143,25 +143,28 @@ export default class OCPIUtilsService {
// Result
const tokens: OCPIToken[] = [];
// Get all tokens
- const tags = await TagStorage.getTags(tenant.id, { issuer: true, dateFrom, dateTo }, { limit, skip });
+ const tags = await TagStorage.getTags(tenant.id,
+ { issuer: true, dateFrom, dateTo, withUsersOnly: true, withUser: true },
+ { limit, skip },
+ [ 'id', 'userID', 'user.deleted', 'lastChangedOn' ]);
// Convert Sites to Locations
for (const tag of tags.result) {
- const user = await UserStorage.getUser(tenant.id, tag.userID);
- const valid = user && !user.deleted;
tokens.push({
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: (tag.id.length % 8 === 0) ? OCPITokenType.RFID : OCPITokenType.OTHER, // Virtual badges handling
auth_id: tag.userID,
visual_number: tag.userID,
issuer: tenant.name,
- valid: valid,
+ valid: !tag.user?.deleted,
whitelist: OCPITokenWhitelist.ALLOWED_OFFLINE,
last_updated: tag.lastChangedOn ? tag.lastChangedOn : new Date()
});
}
let nbrOfTags = tags.count;
if (nbrOfTags === -1) {
- const tagsCount = await TagStorage.getTags(tenant.id, { issuer: true, dateFrom, dateTo }, Constants.DB_PARAMS_COUNT_ONLY);
+ const tagsCount = await TagStorage.getTags(tenant.id,
+ { issuer: true, dateFrom, dateTo, withUsersOnly: true },
+ Constants.DB_PARAMS_COUNT_ONLY);
nbrOfTags = tagsCount.count;
}
return {
@@ -1038,7 +1041,7 @@ export default class OCPIUtilsService {
});
}
if (emspUser) {
- // Existing User: Check local organization
+ // External organization
if (emspUser.issuer) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
@@ -104,7 +104,7 @@ export default class MongoDBStorage {
await this.handleIndexesInCollection(tenantID, 'tags', [
{ fields: { deleted: 1, createdOn: 1 } },
{ fields: { issuer: 1, createdOn: 1 } },
- { fields: { userID: 1 } }
+ { fields: { userID: 1, issuer: 1 } }
]);
// Sites/Users
await this.handleIndexesInCollection(tenantID, 'siteusers', [

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -285,7 +285,7 @@ export default class TagStorage {
public static async getTags(tenantID: string,
params: {
issuer?: boolean; tagIDs?: string[]; userIDs?: string[]; dateFrom?: Date; dateTo?: Date;
- withUser?: boolean; withNbrTransactions?: boolean; search?: string, defaultTag?: boolean, active?: boolean
+ withUser?: boolean; withUsersOnly?: boolean; withNbrTransactions?: boolean; search?: string, defaultTag?: boolean, active?: boolean
},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<Tag>> {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getTags');
@@ -324,6 +324,10 @@ export default class TagStorage {
if (Utils.objectHasProperty(params, 'issuer') && Utils.isBoolean(params.issuer)) {
filters.issuer = params.issuer;
}
+ // With Users only
+ if (params.withUsersOnly) {
+ filters.userID = { $exists: true, $ne: null };
+ }
// Active
if (Utils.objectHasProperty(params, 'active') && Utils.isBoolean(params.active)) {
filters.active = params.active;

Fixed eMSP push of local tag without user not working. Add index in tags. Handle virtual badges as no RFID tags. Limit number of fields returned by the TagStorage.