add visualID in tags context builder / add visualID in virtual tag
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -16,7 +16,6 @@ import AddSiteIDToChargingStationTask from './tasks/AddSiteIDToChargingStationTa
import AddTagTypeTask from './tasks/AddTagTypeTask';
import AddTransactionRefundStatusTask from './tasks/AddTransactionRefundStatusTask';
import AddUserInTransactionsTask from './tasks/AddUserInTransactionsTask';
-import AddVisualIDPropertyToTagsTask from './tasks/AddVisualIDPropertyToTagsTask';
import AlignTagsWithUsersIssuerTask from './tasks/AlignTagsWithUsersIssuerTask';
import ChangeAssetIssuerFieldTask from './tasks/ChangeAssetIssuerFieldTask';
import ChangeCryptoKeyTask from './tasks/ChangeCryptoKeyTask';
@@ -130,7 +129,6 @@ export default class MigrationHandler {
currentMigrationTasks.push(new CleanUpLogicallyDeletedUsersTask());
currentMigrationTasks.push(new CleanUpCarUsersWithDeletedUsersTask());
currentMigrationTasks.push(new ChangeAssetIssuerFieldTask());
- currentMigrationTasks.push(new AddVisualIDPropertyToTagsTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

DELETE
src/migration/tasks/AddVisualIDPropertyToTagsTask.ts
-import Constants from '../../utils/Constants';
-import Cypher from '../../utils/Cypher';
-import Logging from '../../utils/Logging';
-import MigrationTask from '../MigrationTask';
-import { ServerAction } from '../../types/Server';
-import Tenant from '../../types/Tenant';
-import TenantStorage from '../../storage/mongodb/TenantStorage';
-import Utils from '../../utils/Utils';
-import global from '../../types/GlobalType';
-
-const MODULE_NAME = 'AddVisualIDPropertyToTagsTask';
-
-export default class AddVisualIDPropertyToTagsTask extends MigrationTask {
- async migrate(): Promise<void> {
- const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
- for (const tenant of tenants.result) {
- await this.migrateTenant(tenant);
- }
- }
-
- async migrateTenant(tenant: Tenant): Promise<void> {
- // Add the visualID property to tags
- let updated = 0;
- // Get Tags
- const tagsMDB = await global.database.getCollection<any>(tenant.id, 'tags')
- .find({}).toArray();
- if (!Utils.isEmptyArray(tagsMDB)) {
- for (const tagMDB of tagsMDB) {
- await global.database.getCollection<any>(tenant.id, 'tags').findOneAndUpdate(
- { _id: tagMDB._id },
- { $set: { visualID: Cypher.hash(tagMDB._id) } });
- updated++;
- }
- }
- // Log in the default tenant
- if (updated > 0) {
- await Logging.logDebug({
- tenantID: Constants.DEFAULT_TENANT,
- module: MODULE_NAME, method: 'migrateTenant',
- action: ServerAction.MIGRATION,
- message: `${updated} Tag(s) visualID have been updated in Tenant ${Utils.buildTenantName(tenant)}`
- });
- }
- }
-
- getVersion(): string {
- return '1.0';
- }
-
- getName(): string {
- return 'AddVisualIDPropertyToTagsTask';
- }
-
- isAsynchronous(): boolean {
- return true;
- }
-}

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -10,6 +10,7 @@ import AxiosFactory from '../../../../utils/AxiosFactory';
import BillingFactory from '../../../../integration/billing/BillingFactory';
import Configuration from '../../../../utils/Configuration';
import Constants from '../../../../utils/Constants';
+import Cypher from '../../../../utils/Cypher';
import { HTTPError } from '../../../../types/HTTPError';
import I18nManager from '../../../../utils/I18nManager';
import Logging from '../../../../utils/Logging';
@@ -208,6 +209,7 @@ export default class AuthService {
const i18nManager = I18nManager.getInstanceForLocale(newUser.locale);
const tag: Tag = {
id: newUser.name[0] + newUser.firstName[0] + Utils.getRandomIntSafe().toString(),
+ visualID: Cypher.hash(newUser.name[0] + newUser.firstName[0] + Utils.getRandomIntSafe().toString()),
active: true,
issuer: true,
userID: newUser.id,

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
import { AnalyticsSettingsType, BillingSettingsType, PricingSettingsType, RefundSettingsType, RoamingSettingsType, SettingDBContent, SmartChargingSettingsType } from '../../../src/types/Setting';
+import Cypher from '../../../src/utils/Cypher';
import { OCPPVersion } from '../../../src/types/ocpp/OCPPServer';
import { Voltage } from '../../../src/types/ChargingStation';
import faker from 'faker';
@@ -401,6 +402,7 @@ export default class ContextDefinition {
emailPrefix: 'a-unassigned-',
tags: (ContextDefinition.USER_CONTEXTS.ADMIN_UNASSIGNED.withTags ? [{
id: 'A12341',
+ visualID: Cypher.hash('A12341'),
issuer: false,
active: true
}] : null)
@@ -420,6 +422,7 @@ export default class ContextDefinition {
emailPrefix: 'basic-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER.withTags ? [{
id: 'A12342',
+ visualID: Cypher.hash('A12342'),
issuer: false,
active: true
}] : null)
@@ -439,6 +442,7 @@ export default class ContextDefinition {
emailPrefix: 'demo-',
tags: (ContextDefinition.USER_CONTEXTS.DEMO_USER.withTags ? [{
id: 'A12343',
+ visualID: Cypher.hash('A12343'),
issuer: false,
active: true
}] : null)
@@ -458,6 +462,7 @@ export default class ContextDefinition {
emailPrefix: 'b-unassigned-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED.withTags ? [{
id: 'A12348',
+ visualID: Cypher.hash('A12348'),
issuer: false,
active: true
}] : null)
@@ -477,6 +482,7 @@ export default class ContextDefinition {
emailPrefix: 'b-pending-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_PENDING.withTags ? [{
id: 'A12349',
+ visualID: Cypher.hash('A12349'),
issuer: false,
active: true
}] : null)
@@ -496,6 +502,7 @@ export default class ContextDefinition {
emailPrefix: 'b-locked-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_LOCKED.withTags ? [{
id: 'A123410',
+ visualID: Cypher.hash('A123410'),
issuer: false,
active: true
}] : null)
@@ -515,6 +522,7 @@ export default class ContextDefinition {
emailPrefix: 'b-notTag',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_NO_TAGS.withTags ? [{
id: 'A123411',
+ visualID: Cypher.hash('A123411'),
issuer: false,
active: true
}] : null)
@@ -534,6 +542,7 @@ export default class ContextDefinition {
emailPrefix: 'b-external-',
tags: (ContextDefinition.USER_CONTEXTS.EXTERNAL_USER.withTags ? [{
id: 'A220311',
+ visualID: Cypher.hash('A220311'),
issuer: false,
active: true
}] : null)

MODIFY
test/factories/TagFactory.ts
test/factories/TagFactory.ts
+import Cypher from '../../src/utils/Cypher';
import { Factory } from 'rosie';
import faker from 'faker';
export default Factory.define('tag')
.attr('id', () => faker.random.alphaNumeric(20).toString().toUpperCase())
+ .attr('visualID', () => Cypher.hash(faker.random.alphaNumeric(20).toString().toUpperCase()))
.attr('active', true)
.attr('issuer', () => true)
.attr('default', () => false)

add visualID in tags context builder / add visualID in virtual tag