UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

83 lines 2.77 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import request from '../../../../request.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; export const options = z.looseObject({ ...globalOptionsZod.shape, templateId: z.uuid().alias('i') }); class EntraGroupSettingAddCommand extends GraphCommand { get name() { return commands.GROUPSETTING_ADD; } get description() { return 'Creates a group setting'; } allowUnknownOptions() { return true; } get schema() { return options; } async commandAction(logger, args) { if (this.verbose) { await logger.logToStderr(`Retrieving group setting template with id '${args.options.templateId}'...`); } try { let requestOptions = { url: `${this.resource}/v1.0/groupSettingTemplates/${args.options.templateId}`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json' }; const groupSettingTemplate = await request.get(requestOptions); requestOptions = { url: `${this.resource}/v1.0/groupSettings`, headers: { accept: 'application/json;odata.metadata=none', 'content-type': 'application/json' }, data: { templateId: args.options.templateId, values: this.getGroupSettingValues(args.options, groupSettingTemplate) }, responseType: 'json' }; const res = await request.post(requestOptions); await logger.log(res); } catch (err) { this.handleRejectedODataJsonPromise(err); } } getGroupSettingValues(options, groupSettingTemplate) { const values = []; const excludeOptions = [ 'templateId', 'debug', 'verbose', 'output' ]; Object.keys(options).forEach(key => { if (excludeOptions.indexOf(key) === -1) { values.push({ name: key, value: options[key] }); } }); groupSettingTemplate.values.forEach(v => { if (!values.find(e => e.name === v.name)) { values.push({ name: v.name, value: v.defaultValue }); } }); return values; } } export default new EntraGroupSettingAddCommand(); //# sourceMappingURL=groupsetting-add.js.map