UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

79 lines 3 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import { entraGroup } from '../../../../utils/entraGroup.js'; import { odata } from '../../../../utils/odata.js'; import { planner } from '../../../../utils/planner.js'; import { validation } from '../../../../utils/validation.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; export const options = z.strictObject({ ...globalOptionsZod.shape, planId: z.string().optional(), planTitle: z.string().optional(), rosterId: z.string().optional(), ownerGroupId: z.string() .refine(val => validation.isValidGuid(val), { message: 'The value is not a valid GUID.' }) .optional(), ownerGroupName: z.string().optional() }); class PlannerBucketListCommand extends GraphCommand { get name() { return commands.BUCKET_LIST; } get description() { return 'Lists the Microsoft Planner buckets in a plan'; } defaultProperties() { return ['id', 'name', 'planId', 'orderHint']; } get schema() { return options; } getRefinedSchema(schema) { return schema .refine(opts => [opts.planId, opts.planTitle, opts.rosterId].filter(x => x !== undefined).length === 1, { message: `Specify exactly one of the following options: 'planId', 'planTitle' or 'rosterId'.`, params: { customCode: 'optionSet', options: ['planId', 'planTitle', 'rosterId'] } }) .refine(opts => !opts.planTitle || [opts.ownerGroupId, opts.ownerGroupName].filter(x => x !== undefined).length === 1, { message: `Specify exactly one of the following options: 'ownerGroupId' or 'ownerGroupName'.`, params: { customCode: 'optionSet', options: ['ownerGroupId', 'ownerGroupName'] } }); } async commandAction(logger, args) { try { const planId = await this.getPlanId(args); const buckets = await odata.getAllItems(`${this.resource}/v1.0/planner/plans/${planId}/buckets`); await logger.log(buckets); } catch (err) { this.handleRejectedODataJsonPromise(err); } } async getPlanId(args) { if (args.options.planId) { return args.options.planId; } if (args.options.planTitle) { const groupId = await this.getGroupId(args); return planner.getPlanIdByTitle(args.options.planTitle, groupId); } return planner.getPlanIdByRosterId(args.options.rosterId); } async getGroupId(args) { if (args.options.ownerGroupId) { return args.options.ownerGroupId; } return entraGroup.getGroupIdByDisplayName(args.options.ownerGroupName); } } export default new PlannerBucketListCommand(); //# sourceMappingURL=bucket-list.js.map