Add visual ID to tags import
MODIFY
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
},
"description": {
"type": "string"
+ },
+ "visualID": {
+ "type": "string"
}
},
"required": [
"id",
+ "visualID",
"description"
]
}

MODIFY
src/async-task/tasks/TagsImportAsyncTask.ts
src/async-task/tasks/TagsImportAsyncTask.ts
@@ -48,7 +48,8 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
for (const importedTag of importedTags.result) {
try {
// Existing tags
- const foundTag = await TagStorage.getTag(tenant.id, importedTag.id, { withNbrTransactions: true });
+ let foundTag = await TagStorage.getTag(tenant.id, importedTag.id, { withNbrTransactions: true });
+ foundTag = foundTag ? foundTag : await TagStorage.getTagByVisualID(tenant.id, importedTag.visualID);
if (foundTag) {
// Check tag is already in use
if (!foundTag.issuer) {
@@ -63,11 +64,15 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
if (foundTag.transactionsCount > 0) {
throw new Error(`Tag is already used in ${foundTag.transactionsCount} transaction(s)`);
}
+ if (foundTag.id !== importedTag.id) {
+ throw new Error('Tag VisualID is already assigned to another tag');
+ }
tagToSave = { ...foundTag, ...importedTag };
} else {
// New Tag
tagToSave = {
id: importedTag.id,
+ visualID: importedTag.visualID,
description: importedTag.description,
issuer: true,
active: false,

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -776,6 +776,7 @@ export default class TagService {
try {
const newImportedTag: ImportedTag = {
id: importedTag.id.toUpperCase(),
+ visualID: importedTag.visualID,
description: importedTag.description ? importedTag.description : `Badge ID '${importedTag.id}'`,
name: importedTag.name.toUpperCase(),
firstName: importedTag.firstName,

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -43,6 +43,7 @@ export default class TagStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveImportedTag');
const tagMDB = {
_id: importedTagToSave.id,
+ visualID: importedTagToSave.visualID,
description: importedTagToSave.description,
name: importedTagToSave.name,
firstName: importedTagToSave.firstName,
@@ -66,6 +67,7 @@ export default class TagStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveImportedTags');
const importedTagsToSaveMDB: any = importedTagsToSave.map((importedTagToSave) => ({
_id: importedTagToSave.id,
+ visualID: importedTagToSave.visualID,
description: importedTagToSave.description,
name: importedTagToSave.name,
firstName: importedTagToSave.firstName,

MODIFY
src/types/Tag.ts
src/types/Tag.ts
@@ -18,6 +18,7 @@ export default interface Tag extends CreatedUpdatedProps {
export interface ImportedTag {
id: string;
+ visualID?: string;
description: string;
importedBy?: string;
importedOn?: Date;

Add visual ID to tags import