UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

73 lines 2.78 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import { cli } from '../../../../cli/cli.js'; import request from '../../../../request.js'; import { formatting } from '../../../../utils/formatting.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; export const options = z.strictObject({ ...globalOptionsZod.shape, id: z.string().alias('i'), taskId: z.string(), force: z.boolean().optional().alias('f') }); class PlannerTaskChecklistItemRemoveCommand extends GraphCommand { get name() { return commands.TASK_CHECKLISTITEM_REMOVE; } get description() { return 'Removes the checklist item from the planner task'; } get schema() { return options; } async commandAction(logger, args) { if (args.options.force) { await this.removeChecklistitem(args); } else { const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the checklist item with id ${args.options.id} from the planner task?` }); if (result) { await this.removeChecklistitem(args); } } } async removeChecklistitem(args) { try { const task = await this.getTaskDetails(args.options.taskId); if (!task.checklist || !task.checklist[args.options.id]) { throw `The specified checklist item with id ${args.options.id} does not exist`; } const requestOptionsTaskDetails = { url: `${this.resource}/v1.0/planner/tasks/${args.options.taskId}/details`, headers: { 'accept': 'application/json;odata.metadata=none', 'If-Match': task['@odata.etag'], 'Prefer': 'return=representation' }, responseType: 'json', data: { checklist: { [args.options.id]: null } } }; await request.patch(requestOptionsTaskDetails); } catch (err) { this.handleRejectedODataJsonPromise(err); } } async getTaskDetails(taskId) { const requestOptions = { url: `${this.resource}/v1.0/planner/tasks/${formatting.encodeQueryParameter(taskId)}/details?$select=checklist`, headers: { accept: 'application/json;odata.metadata=minimal' }, responseType: 'json' }; return await request.get(requestOptions); } } export default new PlannerTaskChecklistItemRemoveCommand(); //# sourceMappingURL=task-checklistitem-remove.js.map