|
| 1 | +import nifty from "../../nifty.app.mjs"; |
| 2 | +import { parseObjectEntries } from "../../common/utils.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "nifty-create-task", |
| 6 | + name: "Create Task", |
| 7 | + description: "Creates a new task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + nifty, |
| 12 | + projectId: { |
| 13 | + propDefinition: [ |
| 14 | + nifty, |
| 15 | + "projectId", |
| 16 | + ], |
| 17 | + }, |
| 18 | + taskGroupId: { |
| 19 | + propDefinition: [ |
| 20 | + nifty, |
| 21 | + "taskGroupId", |
| 22 | + (c) => ({ |
| 23 | + projectId: c.projectId, |
| 24 | + }), |
| 25 | + ], |
| 26 | + }, |
| 27 | + name: { |
| 28 | + type: "string", |
| 29 | + label: "Name", |
| 30 | + description: "The name of the task", |
| 31 | + }, |
| 32 | + description: { |
| 33 | + type: "string", |
| 34 | + label: "Description", |
| 35 | + description: "A description of the task", |
| 36 | + optional: true, |
| 37 | + }, |
| 38 | + parentTaskId: { |
| 39 | + propDefinition: [ |
| 40 | + nifty, |
| 41 | + "taskId", |
| 42 | + (c) => ({ |
| 43 | + projectId: c.projectId, |
| 44 | + }), |
| 45 | + ], |
| 46 | + label: "Parent Task ID", |
| 47 | + description: "Enter a parent task ID to create this task as subtask of another task", |
| 48 | + optional: true, |
| 49 | + }, |
| 50 | + milestoneId: { |
| 51 | + propDefinition: [ |
| 52 | + nifty, |
| 53 | + "milestoneId", |
| 54 | + (c) => ({ |
| 55 | + projectId: c.projectId, |
| 56 | + }), |
| 57 | + ], |
| 58 | + }, |
| 59 | + dueDate: { |
| 60 | + type: "string", |
| 61 | + label: "Due Date", |
| 62 | + description: "Due date of the task in ISO-8601 format", |
| 63 | + optional: true, |
| 64 | + }, |
| 65 | + startDate: { |
| 66 | + type: "string", |
| 67 | + label: "Start Date", |
| 68 | + description: "Start date of the task in ISO-8601 format", |
| 69 | + optional: true, |
| 70 | + }, |
| 71 | + assigneeIds: { |
| 72 | + propDefinition: [ |
| 73 | + nifty, |
| 74 | + "memberId", |
| 75 | + ], |
| 76 | + type: "string[]", |
| 77 | + label: "Assignee IDs", |
| 78 | + description: "An array of assignee IDs to assign to the task", |
| 79 | + optional: true, |
| 80 | + }, |
| 81 | + labelIds: { |
| 82 | + propDefinition: [ |
| 83 | + nifty, |
| 84 | + "labelIds", |
| 85 | + ], |
| 86 | + }, |
| 87 | + additionalFields: { |
| 88 | + type: "object", |
| 89 | + label: "Additional Fields", |
| 90 | + description: "Additional fields to add to the task. [See the documentation](https://developers.niftypm.com/operation/operation-taskapicontroller_createtask)", |
| 91 | + optional: true, |
| 92 | + }, |
| 93 | + }, |
| 94 | + async run({ $ }) { |
| 95 | + const response = await this.nifty.createTask({ |
| 96 | + $, |
| 97 | + data: { |
| 98 | + task_group_id: this.taskGroupId, |
| 99 | + name: this.name, |
| 100 | + description: this.description, |
| 101 | + task_id: this.parentTaskId, |
| 102 | + milestone_id: this.milestoneId, |
| 103 | + due_date: this.dueDate, |
| 104 | + start_date: this.startDate, |
| 105 | + assignee_ids: this.assigneeIds, |
| 106 | + labels: this.labelIds, |
| 107 | + ...parseObjectEntries(this.additionalFields), |
| 108 | + }, |
| 109 | + }); |
| 110 | + $.export("$summary", `Successfully created task with ID: ${response.id}`); |
| 111 | + return response; |
| 112 | + }, |
| 113 | +}; |
0 commit comments