Skip to content

Commit

Permalink
#1709: correctly log if we were looking for an ID, Key or Name
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Sep 13, 2024
1 parent fbcb9bb commit 295c86a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/User.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/util/util.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions lib/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,17 +840,33 @@ export const Util = {
* @param {boolean} [isId] optional flag to indicate if key is an id
* @returns {string} string to be appended to log message
*/
getKeysString(keyArr, isId) {
getKeysString(keyArr, isId = false) {
if (!keyArr) {
return '';
}
let isName = false;
if (!Array.isArray(keyArr)) {
// if only one key, make it an array
keyArr = [keyArr];
}
if (Array.isArray(keyArr) && keyArr.length === 1) {
// clone it because we don't want our changes to be reflected outside of this function
keyArr = structuredClone(keyArr);

// if we only have one key, we can check if it is an id or name
if (keyArr[0].startsWith('id:')) {
keyArr[0] = keyArr[0].slice(3);
isId = true;
} else if (keyArr[0].startsWith('name:')) {
keyArr[0] = keyArr[0].slice(5);
isName = true;
}
}
const keyType = isId ? 'ID' : isName ? 'Name' : 'Key';

if (keyArr.length > 0) {
return Util.getGrayMsg(
` - ${isId ? 'ID' : 'Key'}${keyArr.length > 1 ? 's' : ''}: ${keyArr.join(', ')}`
` - ${keyType}${keyArr.length > 1 ? 's' : ''}: ${keyArr.join(', ')}`
);
}
return '';
Expand Down

0 comments on commit 295c86a

Please sign in to comment.