From 0a65f5a91a7cb74209447e92208d56fdeb48a88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Fri, 13 Sep 2024 11:23:17 +0200 Subject: [PATCH] #1709: handle 0 users found gracefully --- lib/metadataTypes/User.js | 70 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/lib/metadataTypes/User.js b/lib/metadataTypes/User.js index 41009b8a9..b623a9e8e 100644 --- a/lib/metadataTypes/User.js +++ b/lib/metadataTypes/User.js @@ -694,9 +694,11 @@ class User extends MetadataType { return; } - const metadata = this.parseResponseBody(resultsBulk); - // get BUs that each users have access to + let metadata = {}; if (resultsBulk?.Results?.length > 0) { + metadata = this.parseResponseBody(resultsBulk); + + // get BUs that each users have access to if (!singleRetrieve) { Util.logger.info( Util.getGrayMsg(` - found ${resultsBulk?.Results.length} users`) @@ -736,40 +738,44 @@ class User extends MetadataType { } } } - } - - if (retrieveDir) { - const savedMetadata = await this.saveResults(metadata, retrieveDir, null); - Util.logger.info( - `Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})` + - Util.getKeysString(singleRetrieve) - ); - if (!singleRetrieve) { - // print summary to cli - const counter = { - userActive: 0, - userInactive: 0, - installedPackage: 0, - }; - for (const id in savedMetadata) { - /** @typedef {UserDocument} */ - const item = savedMetadata[id]; - if (item.c__type === 'Installed Package') { - counter.installedPackage++; - } else if (item.ActiveFlag) { - counter.userActive++; - } else { - counter.userInactive++; - } - } + if (retrieveDir) { + const savedMetadata = await this.saveResults(metadata, retrieveDir, null); Util.logger.info( - Util.getGrayMsg( - `Found ${counter.userActive} active users / ${counter.userInactive} inactive users / ${counter.installedPackage} installed packages` - ) + `Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})` + + Util.getKeysString(singleRetrieve) ); + if (!singleRetrieve) { + // print summary to cli + const counter = { + userActive: 0, + userInactive: 0, + installedPackage: 0, + }; + for (const id in savedMetadata) { + /** @typedef {UserDocument} */ + const item = savedMetadata[id]; + if (item.c__type === 'Installed Package') { + counter.installedPackage++; + } else if (item.ActiveFlag) { + counter.userActive++; + } else { + counter.userInactive++; + } + } + Util.logger.info( + Util.getGrayMsg( + `Found ${counter.userActive} active users / ${counter.userInactive} inactive users / ${counter.installedPackage} installed packages` + ) + ); + } + await this.runDocumentOnRetrieve(singleRetrieve, savedMetadata); } - await this.runDocumentOnRetrieve(singleRetrieve, savedMetadata); + } else { + Util.logger.info( + `Downloaded: ${this.definition.type} (0)` + Util.getKeysString(singleRetrieve) + ); } + return { metadata: metadata, type: this.definition.type }; }