@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
119 lines • 5.3 kB
JavaScript
import { z } from 'zod';
import { globalOptionsZod } from '../../../../Command.js';
import { entraGroup } from '../../../../utils/entraGroup.js';
import { formatting } from '../../../../utils/formatting.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,
bucketId: z.string().optional(),
bucketName: z.string().optional(),
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 PlannerTaskListCommand extends GraphCommand {
get name() {
return commands.TASK_LIST;
}
get description() {
return 'Lists planner tasks in a bucket, plan, or tasks for the currently logged in user';
}
get schema() {
return options;
}
defaultProperties() {
return ['id', 'title', 'startDateTime', 'dueDateTime', 'completedDateTime'];
}
getRefinedSchema(schema) {
return schema
.refine(opts => !(opts.bucketId && opts.bucketName), {
message: `Specify either 'bucketId' or 'bucketName', but not both.`,
params: { customCode: 'optionSet', options: ['bucketId', 'bucketName'] }
})
.refine(opts => !(opts.bucketName && !opts.rosterId) || [opts.planId, opts.planTitle].filter(x => x !== undefined).length === 1, {
message: `Specify exactly one of the following options: 'planId' or 'planTitle'.`,
params: { customCode: 'optionSet', options: ['planId', 'planTitle'] }
})
.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) {
const bucketName = args.options.bucketName;
let bucketId = args.options.bucketId;
const planTitle = args.options.planTitle;
let planId = args.options.planId;
let taskItems;
try {
if (bucketId || bucketName) {
bucketId = await this.getBucketId(args);
taskItems = await odata.getAllItems(`${this.resource}/v1.0/planner/buckets/${bucketId}/tasks`);
const betaTasks = await odata.getAllItems(`${this.resource}/beta/planner/buckets/${bucketId}/tasks`);
await logger.log(this.mergeTaskPriority(taskItems, betaTasks));
}
else if (planId || planTitle) {
planId = await this.getPlanId(args);
taskItems = await odata.getAllItems(`${this.resource}/v1.0/planner/plans/${planId}/tasks`);
const betaTasks = await odata.getAllItems(`${this.resource}/beta/planner/plans/${planId}/tasks`);
await logger.log(this.mergeTaskPriority(taskItems, betaTasks));
}
else {
taskItems = await odata.getAllItems(`${this.resource}/v1.0/me/planner/tasks`);
const betaTasks = await odata.getAllItems(`${this.resource}/beta/me/planner/tasks`);
await logger.log(this.mergeTaskPriority(taskItems, betaTasks));
}
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
async getBucketId(args) {
if (args.options.bucketId) {
return formatting.encodeQueryParameter(args.options.bucketId);
}
const planId = await this.getPlanId(args);
return planner.getBucketIdByTitle(args.options.bucketName, planId);
}
async getPlanId(args) {
if (args.options.planId) {
return formatting.encodeQueryParameter(args.options.planId);
}
if (args.options.rosterId) {
return planner.getPlanIdByRosterId(args.options.rosterId);
}
else {
const groupId = await this.getGroupId(args);
return planner.getPlanIdByTitle(args.options.planTitle, groupId);
}
}
async getGroupId(args) {
if (args.options.ownerGroupId) {
return formatting.encodeQueryParameter(args.options.ownerGroupId);
}
return entraGroup.getGroupIdByDisplayName(args.options.ownerGroupName);
}
mergeTaskPriority(taskItems, betaTaskItems) {
const findBetaTask = (id) => betaTaskItems.find(task => task.id === id);
taskItems.forEach(task => {
const betaTaskItem = findBetaTask(task.id);
if (betaTaskItem) {
const { priority } = betaTaskItem;
Object.assign(task, { priority });
}
});
return taskItems;
}
}
export default new PlannerTaskListCommand();
//# sourceMappingURL=task-list.js.map