UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

81 lines 4.18 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _BookingBusinessGetCommand_instances, _BookingBusinessGetCommand_initTelemetry, _BookingBusinessGetCommand_initOptions, _BookingBusinessGetCommand_initOptionSets; import request from '../../../../request.js'; import { formatting } from '../../../../utils/formatting.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; import { cli } from '../../../../cli/cli.js'; class BookingBusinessGetCommand extends GraphCommand { get name() { return commands.BUSINESS_GET; } get description() { return 'Retrieve the specified Microsoft Bookings business.'; } constructor() { super(); _BookingBusinessGetCommand_instances.add(this); __classPrivateFieldGet(this, _BookingBusinessGetCommand_instances, "m", _BookingBusinessGetCommand_initTelemetry).call(this); __classPrivateFieldGet(this, _BookingBusinessGetCommand_instances, "m", _BookingBusinessGetCommand_initOptions).call(this); __classPrivateFieldGet(this, _BookingBusinessGetCommand_instances, "m", _BookingBusinessGetCommand_initOptionSets).call(this); } async commandAction(logger, args) { try { const businessId = await this.getBusinessId(args.options); const requestOptions = { url: `${this.resource}/v1.0/solutions/bookingBusinesses/${formatting.encodeQueryParameter(businessId)}`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json' }; const business = await request.get(requestOptions); await logger.log(business); } catch (err) { this.handleRejectedODataJsonPromise(err); } } async getBusinessId(options) { if (options.id) { return options.id; } const requestOptions = { url: `${this.resource}/v1.0/solutions/bookingBusinesses`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json' }; const response = await request.get(requestOptions); const name = options.name; const bookingBusinesses = response.value.filter(val => val.displayName?.toLocaleLowerCase() === name.toLocaleLowerCase()); if (!bookingBusinesses.length) { throw `The specified business with name ${options.name} does not exist.`; } if (bookingBusinesses.length > 1) { const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', bookingBusinesses); const result = await cli.handleMultipleResultsFound(`Multiple businesses with name '${options.name}' found.`, resultAsKeyValuePair); return result.id; } return bookingBusinesses[0].id; } } _BookingBusinessGetCommand_instances = new WeakSet(), _BookingBusinessGetCommand_initTelemetry = function _BookingBusinessGetCommand_initTelemetry() { this.telemetry.push((args) => { Object.assign(this.telemetryProperties, { id: typeof args.options.id !== 'undefined', name: typeof args.options.name !== 'undefined' }); }); }, _BookingBusinessGetCommand_initOptions = function _BookingBusinessGetCommand_initOptions() { this.options.unshift({ option: '-i, --id [id]' }, { option: '-n, --name [name]' }); }, _BookingBusinessGetCommand_initOptionSets = function _BookingBusinessGetCommand_initOptionSets() { this.optionSets.push({ options: ['id', 'name'] }); }; export default new BookingBusinessGetCommand(); //# sourceMappingURL=business-get.js.map