From e937bf4a9bcd40a8b300b526ea5d8c867b0d0225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3jcik?= Date: Tue, 18 Jul 2023 02:51:29 +0200 Subject: [PATCH] Fixup --- src/m365/aad/commands/app/app-remove.ts | 6 +----- src/m365/aad/commands/app/app-role-add.ts | 6 +----- src/m365/aad/commands/app/app-role-list.ts | 6 +----- src/m365/aad/commands/app/app-role-remove.ts | 12 ++---------- src/m365/aad/commands/app/app-set.ts | 6 +----- .../approleassignment/approleassignment-add.ts | 6 +----- .../o365group/o365group-recyclebinitem-remove.ts | 6 +----- .../o365group/o365group-recyclebinitem-restore.ts | 6 +----- .../aad/commands/o365group/o365group-teamify.ts | 6 +----- src/m365/aad/commands/sp/sp-add.ts | 6 +----- src/m365/aad/commands/sp/sp-get.ts | 6 +----- src/m365/aad/commands/user/user-get.ts | 6 +----- src/m365/booking/commands/business/business-get.ts | 6 +----- src/m365/outlook/commands/message/message-list.ts | 6 +----- src/m365/outlook/commands/message/message-move.ts | 6 +----- src/m365/planner/commands/bucket/bucket-get.ts | 7 ++----- src/m365/planner/commands/bucket/bucket-remove.ts | 7 ++----- src/m365/planner/commands/bucket/bucket-set.ts | 7 ++----- src/m365/planner/commands/task/task-get.ts | 12 ++---------- src/m365/planner/commands/task/task-remove.ts | 13 +++---------- .../commands/aibuildermodel/aibuildermodel-get.ts | 7 ++----- src/m365/pp/commands/card/card-get.ts | 7 ++----- src/m365/pp/commands/chatbot/chatbot-get.ts | 6 +----- .../pp/commands/managementapp/managementapp-add.ts | 6 +----- .../applicationcustomizer-get.ts | 6 +----- .../applicationcustomizer-remove.ts | 6 +----- .../applicationcustomizer-set.ts | 6 +----- src/m365/spo/commands/commandset/commandset-get.ts | 6 +----- .../spo/commands/commandset/commandset-remove.ts | 6 +----- src/m365/spo/commands/commandset/commandset-set.ts | 6 +----- .../spo/commands/customaction/customaction-get.ts | 12 ++---------- .../commands/customaction/customaction-remove.ts | 6 +----- .../spo/commands/eventreceiver/eventreceiver-get.ts | 6 +----- src/m365/spo/commands/hubsite/hubsite-connect.ts | 7 ++----- src/m365/spo/commands/hubsite/hubsite-disconnect.ts | 7 ++----- src/m365/spo/commands/hubsite/hubsite-get.ts | 7 ++----- .../tenant/tenant-applicationcustomizer-get.ts | 6 +----- .../tenant/tenant-applicationcustomizer-remove.ts | 6 +----- .../tenant/tenant-applicationcustomizer-set.ts | 6 +----- .../spo/commands/tenant/tenant-commandset-get.ts | 6 +----- .../spo/commands/tenant/tenant-commandset-remove.ts | 6 +----- src/m365/spo/commands/term/term-get.ts | 6 +----- src/m365/teams/commands/channel/channel-add.ts | 7 ++----- .../teams/commands/channel/channel-member-add.ts | 6 +----- .../teams/commands/channel/channel-member-remove.ts | 6 +----- .../teams/commands/channel/channel-member-set.ts | 6 +----- src/m365/teams/commands/chat/chat-get.ts | 12 ++---------- src/m365/teams/commands/chat/chat-message-send.ts | 13 +++---------- src/utils/aadGroup.ts | 6 +----- 49 files changed, 66 insertions(+), 275 deletions(-) diff --git a/src/m365/aad/commands/app/app-remove.ts b/src/m365/aad/commands/app/app-remove.ts index bbc9c8fe17f..8ca65b89962 100644 --- a/src/m365/aad/commands/app/app-remove.ts +++ b/src/m365/aad/commands/app/app-remove.ts @@ -151,11 +151,7 @@ class AadAppRemoveCommand extends GraphCommand { throw `No Azure AD application registration with ${applicationIdentifier} found`; } - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${name}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${name}' found.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/app/app-role-add.ts b/src/m365/aad/commands/app/app-role-add.ts index 89de8e69478..3777fd07413 100644 --- a/src/m365/aad/commands/app/app-role-add.ts +++ b/src/m365/aad/commands/app/app-role-add.ts @@ -202,11 +202,7 @@ class AadAppRoleAddCommand extends GraphCommand { throw `No Azure AD application registration with ${applicationIdentifier} found`; } - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${appName}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${appName}' found.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/app/app-role-list.ts b/src/m365/aad/commands/app/app-role-list.ts index 45dbc52f7ac..e9ca2c30d80 100644 --- a/src/m365/aad/commands/app/app-role-list.ts +++ b/src/m365/aad/commands/app/app-role-list.ts @@ -106,11 +106,7 @@ class AadAppRoleListCommand extends GraphCommand { throw `No Azure AD application registration with ${applicationIdentifier} found`; } - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${appName}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${appName}' found.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/app/app-role-remove.ts b/src/m365/aad/commands/app/app-role-remove.ts index babedd81612..6832d93de5c 100644 --- a/src/m365/aad/commands/app/app-role-remove.ts +++ b/src/m365/aad/commands/app/app-role-remove.ts @@ -131,11 +131,7 @@ class AadAppRoleRemoveCommand extends GraphCommand { appRoleToDelete !== undefined && appRoleToDelete.length > 1) { - const resultAsKeyValuePair: any = {}; - appRoleToDelete.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', appRoleToDelete); appRoleToDelete[0] = (await Cli.handleMultipleResultsFound(`Multiple roles with name '${args.options.name}' found. Choose the correct ID:`, `Multiple roles with name '${args.options.name}' found.`, resultAsKeyValuePair)) as AppRole; } if (appRoleToDelete.length === 0) { @@ -246,11 +242,7 @@ class AadAppRoleRemoveCommand extends GraphCommand { throw `No Azure AD application registration with ${applicationIdentifier} found`; } - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${appName}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${appName}' found.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/app/app-set.ts b/src/m365/aad/commands/app/app-set.ts index 7bc5c5453ed..2c511a7816a 100644 --- a/src/m365/aad/commands/app/app-set.ts +++ b/src/m365/aad/commands/app/app-set.ts @@ -159,11 +159,7 @@ class AadAppSetCommand extends GraphCommand { throw `No Azure AD application registration with ${applicationIdentifier} found`; } - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${name}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${name}' found.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/approleassignment/approleassignment-add.ts b/src/m365/aad/commands/approleassignment/approleassignment-add.ts index 482df4d22c2..d550e4c2550 100644 --- a/src/m365/aad/commands/approleassignment/approleassignment-add.ts +++ b/src/m365/aad/commands/approleassignment/approleassignment-add.ts @@ -125,11 +125,7 @@ class AadAppRoleAssignmentAddCommand extends GraphCommand { } if (servicePrincipalResult.value.length > 1) { - const resultAsKeyValuePair: any = {}; - servicePrincipalResult.value.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', servicePrincipalResult.value); servicePrincipalResult.value[0] = (await Cli.handleMultipleResultsFound(`Multiple service principal found. Choose the correct ID:`, `More than one service principal found. Please use the appId or appObjectId option to make sure the right service principal is specified.`, resultAsKeyValuePair)) as ServicePrincipal; } diff --git a/src/m365/aad/commands/o365group/o365group-recyclebinitem-remove.ts b/src/m365/aad/commands/o365group/o365group-recyclebinitem-remove.ts index bfb2edd512d..ab61394b052 100644 --- a/src/m365/aad/commands/o365group/o365group-recyclebinitem-remove.ts +++ b/src/m365/aad/commands/o365group/o365group-recyclebinitem-remove.ts @@ -150,11 +150,7 @@ class AadO365GroupRecycleBinItemRemoveCommand extends GraphCommand { } if (groups.length > 1) { - const resultAsKeyValuePair: any = {}; - groups.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', groups); groups[0] = (await Cli.handleMultipleResultsFound(`Multiple groups with name '${displayName || mailNickname}' found. Choose the correct ID:`, `Multiple groups with name '${displayName || mailNickname}' found: ${groups.map(x => x.id).join(',')}.`, resultAsKeyValuePair)) as Group; } diff --git a/src/m365/aad/commands/o365group/o365group-recyclebinitem-restore.ts b/src/m365/aad/commands/o365group/o365group-recyclebinitem-restore.ts index bd0060d8029..7c0287204b5 100644 --- a/src/m365/aad/commands/o365group/o365group-recyclebinitem-restore.ts +++ b/src/m365/aad/commands/o365group/o365group-recyclebinitem-restore.ts @@ -131,11 +131,7 @@ class AadO365GroupRecycleBinItemRestoreCommand extends GraphCommand { } if (groups.length > 1) { - const resultAsKeyValuePair: any = {}; - groups.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', groups); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple groups with name '${displayName || mailNickname}' found. Choose the correct ID:`, `Multiple groups with name '${displayName || mailNickname}' found: ${groups.map(x => x.id).join(',')}.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/o365group/o365group-teamify.ts b/src/m365/aad/commands/o365group/o365group-teamify.ts index 93e082f9e27..a1c1e05925a 100644 --- a/src/m365/aad/commands/o365group/o365group-teamify.ts +++ b/src/m365/aad/commands/o365group/o365group-teamify.ts @@ -91,11 +91,7 @@ class AadO365GroupTeamifyCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Microsoft 365 Groups with name '${args.options.mailNickname}' found. Choose the correct ID:`, `Multiple Microsoft 365 Groups with name '${args.options.mailNickname}' found: ${response.value.map(x => x.id).join(',')}.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/sp/sp-add.ts b/src/m365/aad/commands/sp/sp-add.ts index ac49336b939..587c0199583 100644 --- a/src/m365/aad/commands/sp/sp-add.ts +++ b/src/m365/aad/commands/sp/sp-add.ts @@ -109,11 +109,7 @@ class AadSpAddCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.appId] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('appId', response.value); const result: { appId: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD apps with name '${args.options.appName}' found. Choose the correct ID:`, `Multiple Azure AD apps with name '${args.options.appName}' found: ${response.value.map(x => x.appId).join(',')}.`, resultAsKeyValuePair)) as { appId: string }; return result.appId; } diff --git a/src/m365/aad/commands/sp/sp-get.ts b/src/m365/aad/commands/sp/sp-get.ts index 7bdcb57dcf5..ecca5fe05d9 100644 --- a/src/m365/aad/commands/sp/sp-get.ts +++ b/src/m365/aad/commands/sp/sp-get.ts @@ -109,11 +109,7 @@ class AadSpGetCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple Azure AD apps with name '${args.options.appDisplayName}' found. Choose the correct ID:`, `Multiple Azure AD apps with name '${args.options.appDisplayName}' found: ${response.value.map(x => x.id).join(',')}.`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/aad/commands/user/user-get.ts b/src/m365/aad/commands/user/user-get.ts index e0bf6cfdbc1..8517fcc33ce 100644 --- a/src/m365/aad/commands/user/user-get.ts +++ b/src/m365/aad/commands/user/user-get.ts @@ -123,11 +123,7 @@ class AadUserGetCommand extends GraphCommand { } if (res.value.length > 1) { - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value); res.value[0] = (await Cli.handleMultipleResultsFound(`Multiple users with ${identifier} found. Choose the correct ID:`, `Multiple users with ${identifier} found. Please disambiguate (user names): ${res.value.map(a => a.userPrincipalName).join(', ')} or (ids): ${res.value.map(a => a.id).join(', ')}`, resultAsKeyValuePair)) as User; } diff --git a/src/m365/booking/commands/business/business-get.ts b/src/m365/booking/commands/business/business-get.ts index 24eed03400a..0dfc4145a0a 100644 --- a/src/m365/booking/commands/business/business-get.ts +++ b/src/m365/booking/commands/business/business-get.ts @@ -99,11 +99,7 @@ class BookingBusinessGetCommand extends GraphCommand { } if (bookingBusinesses.length > 1) { - const resultAsKeyValuePair: any = {}; - bookingBusinesses.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', bookingBusinesses); bookingBusinesses[0] = (await Cli.handleMultipleResultsFound(`Multiple businesses with name '${options.name}' found. Choose the correct ID:`, `Multiple businesses with name '${options.name}' found. Please disambiguate: ${bookingBusinesses.map(x => x.id).join(', ')}`, resultAsKeyValuePair)) as BookingBusiness; } diff --git a/src/m365/outlook/commands/message/message-list.ts b/src/m365/outlook/commands/message/message-list.ts index 114bf519356..7c892acbfa4 100644 --- a/src/m365/outlook/commands/message/message-list.ts +++ b/src/m365/outlook/commands/message/message-list.ts @@ -108,11 +108,7 @@ class OutlookMessageListCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); const result: { id: string } = (await Cli.handleMultipleResultsFound(`Multiple folders with name '${args.options.folderName!}' found. Choose the correct ID:`, `Multiple folders with name '${args.options.folderName!}' found. Please disambiguate:${os.EOL}${response.value.map(f => `- ${f.id}`).join(os.EOL)}`, resultAsKeyValuePair)) as { id: string }; return result.id; } diff --git a/src/m365/outlook/commands/message/message-move.ts b/src/m365/outlook/commands/message/message-move.ts index 7cd819af729..aad57f85864 100644 --- a/src/m365/outlook/commands/message/message-move.ts +++ b/src/m365/outlook/commands/message/message-move.ts @@ -131,11 +131,7 @@ class OutlookMessageMoveCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); response.value[0] = (await Cli.handleMultipleResultsFound(`Multiple folders with name '${folderName as string}' found. Choose the correct ID:`, `Multiple folders with name '${folderName as string}' found. Please disambiguate:${os.EOL}${response.value.map(f => `- ${f.id}`).join(os.EOL)}`, resultAsKeyValuePair)) as { id: string; }; } diff --git a/src/m365/planner/commands/bucket/bucket-get.ts b/src/m365/planner/commands/bucket/bucket-get.ts index 4264e0a2246..dc1e768447a 100644 --- a/src/m365/planner/commands/bucket/bucket-get.ts +++ b/src/m365/planner/commands/bucket/bucket-get.ts @@ -8,6 +8,7 @@ import { planner } from '../../../../utils/planner'; import GraphCommand from '../../../base/GraphCommand'; import commands from '../../commands'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -161,11 +162,7 @@ class PlannerBucketGetCommand extends GraphCommand { } if (filteredBuckets.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredBuckets.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredBuckets); filteredBuckets[0] = (await Cli.handleMultipleResultsFound(`Multiple buckets with name '${name}' found. Choose the correct ID:`, `Multiple buckets with name '${name}' found: ${filteredBuckets.map(x => x.id)}`, resultAsKeyValuePair)) as PlannerBucket; } diff --git a/src/m365/planner/commands/bucket/bucket-remove.ts b/src/m365/planner/commands/bucket/bucket-remove.ts index fb7068b9585..df45955c2dd 100644 --- a/src/m365/planner/commands/bucket/bucket-remove.ts +++ b/src/m365/planner/commands/bucket/bucket-remove.ts @@ -8,6 +8,7 @@ import { aadGroup } from '../../../../utils/aadGroup'; import { planner } from '../../../../utils/planner'; import GraphCommand from '../../../base/GraphCommand'; import commands from '../../commands'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -197,11 +198,7 @@ class PlannerBucketRemoveCommand extends GraphCommand { } if (filteredBuckets.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredBuckets.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredBuckets); filteredBuckets[0] = (await Cli.handleMultipleResultsFound(`Multiple buckets with name '${args.options.name}' found. Choose the correct ID:`, `Multiple buckets with name '${args.options.name}' found: ${filteredBuckets.map(x => x.id)}`, resultAsKeyValuePair)) as PlannerBucket; } diff --git a/src/m365/planner/commands/bucket/bucket-set.ts b/src/m365/planner/commands/bucket/bucket-set.ts index 1574522f159..a59f7f8afbc 100644 --- a/src/m365/planner/commands/bucket/bucket-set.ts +++ b/src/m365/planner/commands/bucket/bucket-set.ts @@ -8,6 +8,7 @@ import { planner } from '../../../../utils/planner'; import GraphCommand from '../../../base/GraphCommand'; import commands from '../../commands'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -199,11 +200,7 @@ class PlannerBucketSetCommand extends GraphCommand { } if (filteredBuckets.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredBuckets.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredBuckets); filteredBuckets[0] = (await Cli.handleMultipleResultsFound(`Multiple buckets with name '${args.options.name}' found. Choose the correct ID:`, `Multiple buckets with name '${args.options.name}' found: ${filteredBuckets.map(x => x.id)}`, resultAsKeyValuePair)) as PlannerBucket; } diff --git a/src/m365/planner/commands/task/task-get.ts b/src/m365/planner/commands/task/task-get.ts index 8cd79fdf4cd..9ff8a1cae14 100644 --- a/src/m365/planner/commands/task/task-get.ts +++ b/src/m365/planner/commands/task/task-get.ts @@ -182,11 +182,7 @@ class PlannerTaskGetCommand extends GraphCommand { } if (tasks.length > 1) { - const resultAsKeyValuePair: any = {}; - tasks.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', tasks); tasks[0] = (await Cli.handleMultipleResultsFound(`Multiple tasks with title '${options.title}' found. Choose the correct ID:`, `Multiple tasks with title '${options.title}' found: ${tasks.map(x => x.id)}`, resultAsKeyValuePair)) as PlannerTask; } @@ -216,11 +212,7 @@ class PlannerTaskGetCommand extends GraphCommand { } if (buckets.length > 1) { - const resultAsKeyValuePair: any = {}; - buckets.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', buckets); buckets[0] = (await Cli.handleMultipleResultsFound(`Multiple buckets with name '${options.bucketName}' found. Choose the correct ID:`, `Multiple buckets with name '${options.bucketName}' found: ${buckets.map(x => x.id)}`, resultAsKeyValuePair)) as PlannerBucket; } diff --git a/src/m365/planner/commands/task/task-remove.ts b/src/m365/planner/commands/task/task-remove.ts index f4565c149f9..a2fc032d00d 100644 --- a/src/m365/planner/commands/task/task-remove.ts +++ b/src/m365/planner/commands/task/task-remove.ts @@ -10,6 +10,7 @@ import { validation } from '../../../../utils/validation'; import { planner } from '../../../../utils/planner'; import GraphCommand from '../../../base/GraphCommand'; import commands from '../../commands'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -191,11 +192,7 @@ class PlannerTaskRemoveCommand extends GraphCommand { } if (filteredtasks.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredtasks.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredtasks); filteredtasks[0] = (await Cli.handleMultipleResultsFound(`Multiple tasks with title '${title}' found. Choose the correct ID:`, `Multiple tasks with title '${title}' found: Please disambiguate: ${os.EOL}${filteredtasks.map(f => `- ${f.id}`).join(os.EOL)}`, resultAsKeyValuePair)) as PlannerTask; } @@ -226,11 +223,7 @@ class PlannerTaskRemoveCommand extends GraphCommand { } if (filteredBuckets.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredBuckets.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredBuckets); filteredBuckets[0] = (await Cli.handleMultipleResultsFound(`Multiple buckets with name '${bucketName}' found. Choose the correct ID:`, `Multiple buckets with name '${bucketName}' found: Please disambiguate:${os.EOL}${filteredBuckets.map(f => `- ${f.id}`).join(os.EOL)}`, resultAsKeyValuePair)) as PlannerBucket; } diff --git a/src/m365/pp/commands/aibuildermodel/aibuildermodel-get.ts b/src/m365/pp/commands/aibuildermodel/aibuildermodel-get.ts index 7e97649b2da..07b2e450572 100644 --- a/src/m365/pp/commands/aibuildermodel/aibuildermodel-get.ts +++ b/src/m365/pp/commands/aibuildermodel/aibuildermodel-get.ts @@ -2,6 +2,7 @@ import { Cli } from '../../../../cli/Cli'; import { Logger } from '../../../../cli/Logger'; import GlobalOptions from '../../../../GlobalOptions'; import request, { CliRequestOptions } from '../../../../request'; +import { formatting } from '../../../../utils/formatting'; import { powerPlatform } from '../../../../utils/powerPlatform'; import { validation } from '../../../../utils/validation'; import PowerPlatformCommand from '../../../base/PowerPlatformCommand'; @@ -123,11 +124,7 @@ class PpAiBuilderModelGetCommand extends PowerPlatformCommand { } if (result.value.length > 1) { - const resultAsKeyValuePair: any = {}; - result.value.forEach((obj) => { - resultAsKeyValuePair[obj.msdyn_aimodelid!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('msdyn_aimodelid', result.value); result.value[0] = (await Cli.handleMultipleResultsFound(`Multiple AI builder models with name '${options.name}' found. Choose the correct ID:`, `Multiple AI builder models with name '${options.name}' found: ${result.value.map(x => x.msdyn_aimodelid).join(',')}`, resultAsKeyValuePair)); } diff --git a/src/m365/pp/commands/card/card-get.ts b/src/m365/pp/commands/card/card-get.ts index a2b9bb08dcc..2e58a3d9d35 100644 --- a/src/m365/pp/commands/card/card-get.ts +++ b/src/m365/pp/commands/card/card-get.ts @@ -6,6 +6,7 @@ import commands from '../../commands'; import request, { CliRequestOptions } from '../../../../request'; import { validation } from '../../../../utils/validation'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -124,11 +125,7 @@ class PpCardGetCommand extends PowerPlatformCommand { } if (result.value.length > 1) { - const resultAsKeyValuePair: any = {}; - result.value.forEach((obj) => { - resultAsKeyValuePair[obj.cardid] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('cardid', result.value); return Cli.handleMultipleResultsFound(`Multiple cards with name '${options.name}' found. Choose the correct ID:`, `Multiple cards with name '${options.name}' found.`, resultAsKeyValuePair); } diff --git a/src/m365/pp/commands/chatbot/chatbot-get.ts b/src/m365/pp/commands/chatbot/chatbot-get.ts index 2067695bfc3..377260fbb0b 100644 --- a/src/m365/pp/commands/chatbot/chatbot-get.ts +++ b/src/m365/pp/commands/chatbot/chatbot-get.ts @@ -121,11 +121,7 @@ class PpChatbotGetCommand extends PowerPlatformCommand { const result = await request.get<{ value: any[] }>(requestOptions); if (result.value.length > 1) { - const resultAsKeyValuePair: any = {}; - result.value.forEach((obj) => { - resultAsKeyValuePair[obj.botid!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('botid', result.value); result.value[0] = (await Cli.handleMultipleResultsFound(`Multiple chatbots with name '${options.name}' found. Choose the correct ID:`, `Multiple chatbots with name '${options.name}' found: ${result.value.map(x => x.botid).join(',')}`, resultAsKeyValuePair)); } diff --git a/src/m365/pp/commands/managementapp/managementapp-add.ts b/src/m365/pp/commands/managementapp/managementapp-add.ts index 2f2025bf3de..f9e3a4c427e 100644 --- a/src/m365/pp/commands/managementapp/managementapp-add.ts +++ b/src/m365/pp/commands/managementapp/managementapp-add.ts @@ -125,11 +125,7 @@ class PpManagementAppAddCommand extends PowerPlatformCommand { return aadApps.value[0].appId; } - const resultAsKeyValuePair: any = {}; - aadApps.value.forEach((obj) => { - resultAsKeyValuePair[obj.appId!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('appId', aadApps.value); const result: Application = (await Cli.handleMultipleResultsFound(`Multiple Azure AD application registration with name '${name}' found. Choose the correct ID:`, `Multiple Azure AD application registration with name '${name}' found. Please disambiguate (app IDs): ${aadApps.value.map(a => a.appId).join(', ')}`, resultAsKeyValuePair)) as Application; return result.appId!; } diff --git a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.ts b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.ts index 6a93993b467..4be46b87ecf 100644 --- a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.ts +++ b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-get.ts @@ -152,11 +152,7 @@ class SpoApplicationCustomizerGetCommand extends SpoCommand { throw `No application customizer with ${identifier} found`; } else { - const resultAsKeyValuePair: any = {}; - customActions.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', customActions); return (await Cli.handleMultipleResultsFound(`Multiple application customizers with ${identifier} found. Choose the correct ID:`, `Multiple application customizers with ${identifier} found. Please disambiguate using IDs: ${customActions.map(a => a.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; } } diff --git a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-remove.ts b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-remove.ts index a172a47ebd6..402ab803c98 100644 --- a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-remove.ts +++ b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-remove.ts @@ -167,11 +167,7 @@ class SpoApplicationCustomizerRemoveCommand extends SpoCommand { } if (appCustomizers.length > 1) { - const resultAsKeyValuePair: any = {}; - appCustomizers.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', appCustomizers); return (await Cli.handleMultipleResultsFound(`Multiple application customizer with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Choose the correct ID:`, `Multiple application customizer with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Please disambiguate using IDs: ${os.EOL}${appCustomizers.map(a => `- ${a.Id}`).join(os.EOL)}`, resultAsKeyValuePair)) as CustomAction; } diff --git a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-set.ts b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-set.ts index 976ff94db90..39126f4437b 100644 --- a/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-set.ts +++ b/src/m365/spo/commands/applicationcustomizer/applicationcustomizer-set.ts @@ -181,11 +181,7 @@ class SpoApplicationCustomizerSetCommand extends SpoCommand { } if (appCustomizers.length > 1) { - const resultAsKeyValuePair: any = {}; - appCustomizers.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', appCustomizers); return (await Cli.handleMultipleResultsFound(`Multiple application customizer with ${title ? `title '${title}'` : `ClientSideComponentId '${clientSideComponentId}'`} found. Choose the correct ID:`, `Multiple application customizer with ${title ? `title '${title}'` : `ClientSideComponentId '${clientSideComponentId}'`} found. Please disambiguate using IDs: ${os.EOL}${appCustomizers.map(a => `- ${a.Id}`).join(os.EOL)}`, resultAsKeyValuePair)) as CustomAction; } diff --git a/src/m365/spo/commands/commandset/commandset-get.ts b/src/m365/spo/commands/commandset/commandset-get.ts index 359d4563e43..064f4f75c0f 100644 --- a/src/m365/spo/commands/commandset/commandset-get.ts +++ b/src/m365/spo/commands/commandset/commandset-get.ts @@ -136,11 +136,7 @@ class SpoCommandSetGetCommand extends SpoCommand { throw `No command set with title '${args.options.title}' found.`; } else { - const resultAsKeyValuePair: any = {}; - commandSets.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', commandSets); const commandSet = (await Cli.handleMultipleResultsFound(`Multiple command sets with title '${args.options.title}' found. Choose the correct ID:`, `Multiple command sets with title '${args.options.title}' found. Please disambiguate using IDs: ${os.EOL}${commandSets.map(commandSet => `- ${commandSet.Id}`).join(os.EOL)}.`, resultAsKeyValuePair)) as CustomAction; logger.log(commandSet); } diff --git a/src/m365/spo/commands/commandset/commandset-remove.ts b/src/m365/spo/commands/commandset/commandset-remove.ts index 6dadd310809..63a8d8534d5 100644 --- a/src/m365/spo/commands/commandset/commandset-remove.ts +++ b/src/m365/spo/commands/commandset/commandset-remove.ts @@ -146,11 +146,7 @@ class SpoCommandSetRemoveCommand extends SpoCommand { } if (commandSets.length > 1) { - const resultAsKeyValuePair: any = {}; - commandSets.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', commandSets); commandSets[0] = (await Cli.handleMultipleResultsFound(`Multiple user commandsets with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Choose the correct ID:`, `Multiple user commandsets with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Please disambiguate using IDs: ${commandSets.map((commandSet: CustomAction) => commandSet.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; } diff --git a/src/m365/spo/commands/commandset/commandset-set.ts b/src/m365/spo/commands/commandset/commandset-set.ts index a13ecfbdae0..36b6493fde9 100644 --- a/src/m365/spo/commands/commandset/commandset-set.ts +++ b/src/m365/spo/commands/commandset/commandset-set.ts @@ -214,11 +214,7 @@ class SpoCommandSetSetCommand extends SpoCommand { } if (commandSets.length > 1) { - const resultAsKeyValuePair: any = {}; - commandSets.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', commandSets); commandSets[0] = (await Cli.handleMultipleResultsFound(`Multiple user commandsets with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Choose the correct ID:`, `Multiple user commandsets with ${options.title ? `title '${options.title}'` : `ClientSideComponentId '${options.clientSideComponentId}'`} found. Please disambiguate using IDs: ${commandSets.map((commandSet: CustomAction) => commandSet.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; } diff --git a/src/m365/spo/commands/customaction/customaction-get.ts b/src/m365/spo/commands/customaction/customaction-get.ts index 70909caf752..21c7e32a4fd 100644 --- a/src/m365/spo/commands/customaction/customaction-get.ts +++ b/src/m365/spo/commands/customaction/customaction-get.ts @@ -157,11 +157,7 @@ class SpoCustomActionGetCommand extends SpoCommand { throw `No user custom action with title '${options.title}' found`; } - const resultAsKeyValuePair: any = {}; - customActions.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', customActions); return (await Cli.handleMultipleResultsFound(`Multiple user custom actions with title '${options.title}' found. Choose the correct ID:`, `Multiple user custom actions with title '${options.title}' found. Please disambiguate using IDs: ${customActions.map(a => a.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; } else { @@ -172,11 +168,7 @@ class SpoCustomActionGetCommand extends SpoCommand { } if (customActions.length > 1) { - const resultAsKeyValuePair: any = {}; - customActions.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', customActions); return (await Cli.handleMultipleResultsFound(`Multiple user custom actions with ClientSideComponentId '${options.clientSideComponentId}' found. Choose the correct ID:`, `Multiple user custom actions with ClientSideComponentId '${options.clientSideComponentId}' found. Please disambiguate using IDs: ${customActions.map((customAction: CustomAction) => customAction.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; } diff --git a/src/m365/spo/commands/customaction/customaction-remove.ts b/src/m365/spo/commands/customaction/customaction-remove.ts index 191bb98573e..352b4e99712 100644 --- a/src/m365/spo/commands/customaction/customaction-remove.ts +++ b/src/m365/spo/commands/customaction/customaction-remove.ts @@ -152,11 +152,7 @@ class SpoCustomActionRemoveCommand extends SpoCommand { throw `No user custom action with title '${options.title}' found`; } - const resultAsKeyValuePair: any = {}; - customActions.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', customActions); const result = (await Cli.handleMultipleResultsFound(`Multiple user custom actions with title '${options.title}' found. Choose the correct ID:`, `Multiple user custom actions with title '${options.title}' found. Please disambiguate using IDs: ${customActions.map(a => a.Id).join(', ')}`, resultAsKeyValuePair)) as CustomAction; return result.Id; } diff --git a/src/m365/spo/commands/eventreceiver/eventreceiver-get.ts b/src/m365/spo/commands/eventreceiver/eventreceiver-get.ts index 60a21d2269a..ad2b534dabd 100644 --- a/src/m365/spo/commands/eventreceiver/eventreceiver-get.ts +++ b/src/m365/spo/commands/eventreceiver/eventreceiver-get.ts @@ -178,11 +178,7 @@ class SpoEventreceiverGetCommand extends SpoCommand { } if (res.value && res.value.length > 1) { - const resultAsKeyValuePair: any = {}; - res.value.forEach((obj) => { - resultAsKeyValuePair[obj.ReceiverId] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('ReceiverId', res.value); return (await Cli.handleMultipleResultsFound(`Multiple event receivers with name '${args.options.name}' found. Choose the correct ID:`, `Multiple event receivers with name '${args.options.name}' found: ${res.value.map(x => x.ReceiverId)}`, resultAsKeyValuePair)) as EventReceiver; } diff --git a/src/m365/spo/commands/hubsite/hubsite-connect.ts b/src/m365/spo/commands/hubsite/hubsite-connect.ts index 49afa69dd19..b684ddfa0c2 100644 --- a/src/m365/spo/commands/hubsite/hubsite-connect.ts +++ b/src/m365/spo/commands/hubsite/hubsite-connect.ts @@ -7,6 +7,7 @@ import { HubSite } from './HubSite'; import request, { CliRequestOptions } from '../../../../request'; import { spo } from '../../../../utils/spo'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -175,11 +176,7 @@ class SpoHubSiteConnectCommand extends SpoCommand { throw `The specified hub site '${id || title || url}' does not exist.`; } if (filteredHubSites.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredHubSites.forEach((obj) => { - resultAsKeyValuePair[obj.ID] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('ID', filteredHubSites); return (await Cli.handleMultipleResultsFound(`Multiple hub sites with name '${title}' found. Choose the correct ID:`, `Multiple hub sites with name '${title}' found: ${filteredHubSites.map(s => s.ID).join(',')}.`, resultAsKeyValuePair)) as HubSite; } diff --git a/src/m365/spo/commands/hubsite/hubsite-disconnect.ts b/src/m365/spo/commands/hubsite/hubsite-disconnect.ts index d2c49d3463d..a59130f4b3e 100644 --- a/src/m365/spo/commands/hubsite/hubsite-disconnect.ts +++ b/src/m365/spo/commands/hubsite/hubsite-disconnect.ts @@ -2,6 +2,7 @@ import { Cli } from '../../../../cli/Cli'; import { Logger } from '../../../../cli/Logger'; import GlobalOptions from '../../../../GlobalOptions'; import request, { CliRequestOptions } from '../../../../request'; +import { formatting } from '../../../../utils/formatting'; import { spo } from '../../../../utils/spo'; import { validation } from '../../../../utils/validation'; import SpoCommand from '../../../base/SpoCommand'; @@ -167,11 +168,7 @@ class SpoHubSiteDisconnectCommand extends SpoCommand { throw `The specified hub site '${options.title || options.url}' does not exist.`; } if (filteredHubSites.length > 1) { - const resultAsKeyValuePair: any = {}; - filteredHubSites.forEach((obj) => { - resultAsKeyValuePair[obj.ID] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('ID', filteredHubSites); filteredHubSites[0] = (await Cli.handleMultipleResultsFound(`Multiple hub sites with name '${options.title}' found. Choose the correct ID:`, `Multiple hub sites with name '${options.title}' found: ${filteredHubSites.map(s => s.ID).join(',')}.`, resultAsKeyValuePair)) as HubSite; } diff --git a/src/m365/spo/commands/hubsite/hubsite-get.ts b/src/m365/spo/commands/hubsite/hubsite-get.ts index bdd8341c20c..31396f5ecf2 100644 --- a/src/m365/spo/commands/hubsite/hubsite-get.ts +++ b/src/m365/spo/commands/hubsite/hubsite-get.ts @@ -4,6 +4,7 @@ import { Logger } from '../../../../cli/Logger'; import Command from '../../../../Command'; import GlobalOptions from '../../../../GlobalOptions'; import request, { CliRequestOptions } from '../../../../request'; +import { formatting } from '../../../../utils/formatting'; import { spo } from '../../../../utils/spo'; import { validation } from '../../../../utils/validation'; import SpoCommand from '../../../base/SpoCommand'; @@ -154,11 +155,7 @@ class SpoHubSiteGetCommand extends SpoCommand { } if (hubSites.length > 1) { - const resultAsKeyValuePair: any = {}; - hubSites.forEach((obj) => { - resultAsKeyValuePair[obj.ID] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('ID', hubSites); hubSites[0] = (await Cli.handleMultipleResultsFound(`Multiple hub sites with ${options.title || options.url} found. Choose the correct ID:`, `Multiple hub sites with ${options.title || options.url} found. Please disambiguate: ${hubSites.map(site => site.SiteUrl).join(', ')}`, resultAsKeyValuePair)) as HubSite; } diff --git a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-get.ts b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-get.ts index 2bc5f70e071..a694ff547ea 100644 --- a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-get.ts +++ b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-get.ts @@ -110,11 +110,7 @@ class SpoTenantApplicationCustomizerGetCommand extends SpoCommand { } if (listItemInstances.length > 1) { - const resultAsKeyValuePair: any = {}; - listItemInstances.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances); listItemInstances[0] = (await Cli.handleMultipleResultsFound(`Multiple application customizers with ${args.options.title || args.options.clientSideComponentId} were found.`, `Multiple application customizers with ${args.options.title || args.options.clientSideComponentId} were found. Please disambiguate (IDs): ${listItemInstances.map(item => item.GUID).join(', ')}`, resultAsKeyValuePair)) as ListItemInstance; } diff --git a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-remove.ts b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-remove.ts index c4103d927a8..089a1caa334 100644 --- a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-remove.ts +++ b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-remove.ts @@ -137,11 +137,7 @@ class SpoTenantApplicationCustomizerRemoveCommand extends SpoCommand { } if (listItemInstances.length > 1) { - const resultAsKeyValuePair: any = {}; - listItemInstances.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances); listItemInstances[0] = (await Cli.handleMultipleResultsFound(`Multiple application customizers with ${args.options.title || args.options.clientSideComponentId} were found. Choose the correct ID:`, `Multiple application customizers with ${args.options.title || args.options.clientSideComponentId} were found. Please disambiguate (IDs): ${listItemInstances.map(item => item.Id).join(', ')}`, resultAsKeyValuePair)) as ListItemInstance; } diff --git a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-set.ts b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-set.ts index 27e5b542580..42499e059d7 100644 --- a/src/m365/spo/commands/tenant/tenant-applicationcustomizer-set.ts +++ b/src/m365/spo/commands/tenant/tenant-applicationcustomizer-set.ts @@ -171,11 +171,7 @@ class SpoTenantApplicationCustomizerSetCommand extends SpoCommand { } if (listItemInstances.length > 1) { - const resultAsKeyValuePair: any = {}; - listItemInstances.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances); listItemInstances[0] = (await Cli.handleMultipleResultsFound(`Multiple application customizers with ${title ? `title '${title}'` : `ClientSideComponentId '${clientSideComponentId}'`} found. Choose the correct ID:`, `Multiple application customizers with ${title ? `title '${title}'` : `ClientSideComponentId '${clientSideComponentId}'`} found. Please disambiguate using IDs: ${os.EOL}${listItemInstances.map(item => `- ${(item as any).Id}`).join(os.EOL)}`, resultAsKeyValuePair)) as ListItemInstance; } diff --git a/src/m365/spo/commands/tenant/tenant-commandset-get.ts b/src/m365/spo/commands/tenant/tenant-commandset-get.ts index 3058dc15410..a000e63ded4 100644 --- a/src/m365/spo/commands/tenant/tenant-commandset-get.ts +++ b/src/m365/spo/commands/tenant/tenant-commandset-get.ts @@ -116,11 +116,7 @@ class SpoTenantCommandSetGetCommand extends SpoCommand { if (listItemInstances?.value.length > 0) { if (listItemInstances.value.length > 1) { - const resultAsKeyValuePair: any = {}; - listItemInstances.value.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances.value); listItemInstances.value[0] = (await Cli.handleMultipleResultsFound(`Multiple ListView Command Sets with ${args.options.title || args.options.clientSideComponentId} were found. Choose the correct ID:`, `Multiple ListView Command Sets with ${args.options.title || args.options.clientSideComponentId} were found. Please disambiguate (IDs): ${listItemInstances.value.map(item => item.Id).join(', ')}`, resultAsKeyValuePair)) as ListItemInstance; } diff --git a/src/m365/spo/commands/tenant/tenant-commandset-remove.ts b/src/m365/spo/commands/tenant/tenant-commandset-remove.ts index c9eabf1d46d..6ecc98c0411 100644 --- a/src/m365/spo/commands/tenant/tenant-commandset-remove.ts +++ b/src/m365/spo/commands/tenant/tenant-commandset-remove.ts @@ -167,11 +167,7 @@ class SpoTenantCommandSetRemoveCommand extends SpoCommand { } if (listItemInstances.length > 1) { - const resultAsKeyValuePair: any = {}; - listItemInstances.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', listItemInstances); listItemInstances[0] = (await Cli.handleMultipleResultsFound(`Multiple command sets with ${args.options.title || args.options.clientSideComponentId} were found. Choose the correct ID:`, `Multiple command sets with ${args.options.title || args.options.clientSideComponentId} were found. Please disambiguate (IDs): ${listItemInstances.map(item => item.Id).join(', ')}`, resultAsKeyValuePair)) as ListItemInstance; } diff --git a/src/m365/spo/commands/term/term-get.ts b/src/m365/spo/commands/term/term-get.ts index 41ce5c15165..dd0dd0d5445 100644 --- a/src/m365/spo/commands/term/term-get.ts +++ b/src/m365/spo/commands/term/term-get.ts @@ -165,11 +165,7 @@ class SpoTermGetCommand extends SpoCommand { return `- ${this.getTermId(c.Id)} - ${c.PathOfTerm}`; }).join(os.EOL); - const resultAsKeyValuePair: any = {}; - terms._Child_Items_.forEach((obj) => { - resultAsKeyValuePair[obj.Id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('Id', terms._Child_Items_); terms._Child_Items_[0] = (await Cli.handleMultipleResultsFound(`Multiple terms with the specific term name found. Choose the correct ID:`, `Multiple terms with the specific term name found. Please disambiguate:${os.EOL}${disambiguationText}`, resultAsKeyValuePair)) as Term; } diff --git a/src/m365/teams/commands/channel/channel-add.ts b/src/m365/teams/commands/channel/channel-add.ts index b824728cafa..d19a548bd1c 100644 --- a/src/m365/teams/commands/channel/channel-add.ts +++ b/src/m365/teams/commands/channel/channel-add.ts @@ -6,6 +6,7 @@ import { validation } from '../../../../utils/validation'; import GraphCommand from "../../../base/GraphCommand"; import commands from '../../commands'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -126,11 +127,7 @@ class TeamsChannelAddCommand extends GraphCommand { } if (matchingTeams.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); matchingTeams[0] = ((await Cli.handleMultipleResultsFound(`Multiple Microsoft Teams teams with name ${args.options.teamName} found. Choose the correct ID:`, `Multiple Microsoft Teams teams with name ${args.options.teamName} found: ${matchingTeams.join(', ')}`, resultAsKeyValuePair)) as Team).id!; } diff --git a/src/m365/teams/commands/channel/channel-member-add.ts b/src/m365/teams/commands/channel/channel-member-add.ts index 0fe3ad777c0..7c03820ecac 100644 --- a/src/m365/teams/commands/channel/channel-member-add.ts +++ b/src/m365/teams/commands/channel/channel-member-add.ts @@ -220,11 +220,7 @@ class TeamsChannelMemberAddCommand extends GraphCommand { } if (response.value.length > 1) { - const resultAsKeyValuePair: any = {}; - response.value.forEach((obj) => { - resultAsKeyValuePair[obj.id] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value); return ((await Cli.handleMultipleResultsFound(`Multiple users with display name '${userDisplayName}' found. Choose the correct ID:`, `Multiple users with display name '${userDisplayName}' found. Please disambiguate:${os.EOL}${response.value.map(x => `- ${x.id}`).join(os.EOL)}`, resultAsKeyValuePair)) as any).id; } diff --git a/src/m365/teams/commands/channel/channel-member-remove.ts b/src/m365/teams/commands/channel/channel-member-remove.ts index 2dacd557612..051f02b5640 100644 --- a/src/m365/teams/commands/channel/channel-member-remove.ts +++ b/src/m365/teams/commands/channel/channel-member-remove.ts @@ -245,11 +245,7 @@ class TeamsChannelMemberRemoveCommand extends GraphCommand { } if (conversationMembers.length > 1) { - const resultAsKeyValuePair: any = {}; - conversationMembers.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', conversationMembers); return ((await Cli.handleMultipleResultsFound(`Multiple Microsoft Teams channel members with name ${args.options.userName} found. Choose the correct ID:`, `Multiple Microsoft Teams channel members with name ${args.options.userName} found: ${response.value.map(x => x.userId)}`, resultAsKeyValuePair)) as any).id; } diff --git a/src/m365/teams/commands/channel/channel-member-set.ts b/src/m365/teams/commands/channel/channel-member-set.ts index 1eda1dce25f..568ee244723 100644 --- a/src/m365/teams/commands/channel/channel-member-set.ts +++ b/src/m365/teams/commands/channel/channel-member-set.ts @@ -224,11 +224,7 @@ class TeamsChannelMemberSetCommand extends GraphCommand { } if (conversationMembers.length > 1) { - const resultAsKeyValuePair: any = {}; - conversationMembers.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', conversationMembers); return ((await Cli.handleMultipleResultsFound(`Multiple Microsoft Teams channel members with name ${args.options.userName} found. Choose the correct ID:`, `Multiple Microsoft Teams channel members with name ${args.options.userName} found: ${response.value.map(x => x.userId)}`, resultAsKeyValuePair)) as any).id; } diff --git a/src/m365/teams/commands/chat/chat-get.ts b/src/m365/teams/commands/chat/chat-get.ts index c6ae258635d..90d0a5902f7 100644 --- a/src/m365/teams/commands/chat/chat-get.ts +++ b/src/m365/teams/commands/chat/chat-get.ts @@ -137,11 +137,7 @@ class TeamsChatGetCommand extends GraphCommand { return `- ${c.id}${c.topic && ' - '}${c.topic} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()}`; }).join(os.EOL); - const resultAsKeyValuePair: any = {}; - existingChats.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', existingChats); return ((await Cli.handleMultipleResultsFound(`Multiple chat conversations with these participants found. Choose the correct ID:`, `Multiple chat conversations with these participants found. Please disambiguate:${os.EOL}${disambiguationText}`, resultAsKeyValuePair)) as Chat).id!; } @@ -161,11 +157,7 @@ class TeamsChatGetCommand extends GraphCommand { return `- ${c.id} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()} - ${memberstring}`; }).join(os.EOL); - const resultAsKeyValuePair: any = {}; - existingChats.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', existingChats); return ((await Cli.handleMultipleResultsFound(`Multiple chat conversations with this name found. Choose the correct ID:`, `Multiple chat conversations with this name found. Please disambiguate:${os.EOL}${disambiguationText}`, resultAsKeyValuePair)) as Chat).id!; } } diff --git a/src/m365/teams/commands/chat/chat-message-send.ts b/src/m365/teams/commands/chat/chat-message-send.ts index 38eb839d6da..c5b11d34f76 100644 --- a/src/m365/teams/commands/chat/chat-message-send.ts +++ b/src/m365/teams/commands/chat/chat-message-send.ts @@ -10,6 +10,7 @@ import GraphCommand from '../../../base/GraphCommand'; import commands from '../../commands'; import { chatUtil } from './chatUtil'; import { Cli } from '../../../../cli/Cli'; +import { formatting } from '../../../../utils/formatting'; interface CommandArgs { options: Options; @@ -128,11 +129,7 @@ class TeamsChatMessageSendCommand extends GraphCommand { return `- ${c.id}${c.topic && ' - '}${c.topic} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()}`; }).join(os.EOL); - const resultAsKeyValuePair: any = {}; - existingChats.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', existingChats); return ((await Cli.handleMultipleResultsFound(`Multiple chat conversations with this name found. Choose the correct ID:`, `Multiple chat conversations with this name found. Please disambiguate:${os.EOL}${disambiguationText}`, resultAsKeyValuePair)) as Chat).id!; } @@ -152,11 +149,7 @@ class TeamsChatMessageSendCommand extends GraphCommand { return `- ${c.id} - ${c.createdDateTime && new Date(c.createdDateTime).toLocaleString()} - ${memberstring}`; }).join(os.EOL); - const resultAsKeyValuePair: any = {}; - existingChats.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', existingChats); return ((await Cli.handleMultipleResultsFound(`Multiple chat conversations with this name found. Choose the correct ID:`, `Multiple chat conversations with this name found. Please disambiguate:${os.EOL}${disambiguationText}`, resultAsKeyValuePair)) as Chat).id!; } diff --git a/src/utils/aadGroup.ts b/src/utils/aadGroup.ts index 801d4822c01..1dbb2fa2963 100644 --- a/src/utils/aadGroup.ts +++ b/src/utils/aadGroup.ts @@ -45,11 +45,7 @@ export const aadGroup = { } if (groups.length > 1) { - const resultAsKeyValuePair: any = {}; - groups.forEach((obj) => { - resultAsKeyValuePair[obj.id!] = obj; - }); - + const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', groups); groups[0] = (await Cli.handleMultipleResultsFound(`Multiple groups with name '${displayName}' found. Choose the correct ID:`, `Multiple groups with name '${displayName}' found: ${groups.map(x => x.id).join(',')}.`, resultAsKeyValuePair)) as Group; }