Skip to content

Commit

Permalink
#1709: handle 0 users found gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Sep 13, 2024
1 parent 295c86a commit 0a65f5a
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions lib/metadataTypes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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 };
}

Expand Down

0 comments on commit 0a65f5a

Please sign in to comment.