Skip to content

Commit

Permalink
fix: Update ClickUp API's UpdateTask method to use TaskUpdateRequest …
Browse files Browse the repository at this point in the history
…instead of TaskRequest. Fixed assignees update struct
  • Loading branch information
Jonathan Schmitt committed Jun 28, 2024
1 parent 349bbbf commit ac90cf7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
27 changes: 26 additions & 1 deletion clickup/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ type TaskRequest struct {
CustomItemId int `json:"custom_item_id,omitempty"` // To create a task that doesn't use a custom task type, either don't include this field in the request body, or send 'null'. To create this task as a Milestone, send a value of 1. To use a custom task type, send the custom task type ID as defined in your Workspace, such as 2.
}

type TaskUpdateRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Assignees TaskAssigneeUpdateRequest `json:"assignees,omitempty"`
Tags []string `json:"tags,omitempty"`
Status string `json:"status,omitempty"`
Priority int `json:"priority,omitempty"`
DueDate *Date `json:"due_date,omitempty"`
DueDateTime bool `json:"due_date_time,omitempty"`
TimeEstimate int `json:"time_estimate,omitempty"`
StartDate *Date `json:"start_date,omitempty"`
StartDateTime bool `json:"start_date_time,omitempty"`
NotifyAll bool `json:"notify_all,omitempty"`
Parent string `json:"parent,omitempty"`
LinksTo string `json:"links_to,omitempty"`
CheckRequiredCustomFields bool `json:"check_required_custom_fields,omitempty"`
CustomFields []CustomFieldInTaskRequest `json:"custom_fields,omitempty"`
CustomItemId int `json:"custom_item_id,omitempty"` // To create a task that doesn't use a custom task type, either don't include this field in the request body, or send 'null'. To create this task as a Milestone, send a value of 1. To use a custom task type, send the custom task type ID as defined in your Workspace, such as 2.
}

type TaskAssigneeUpdateRequest struct {
Add []int `json:"add,omitempty"`
Rem []int `json:"rem,omitempty"`
}

type CustomFieldInTaskRequest struct {
ID string `json:"id"`
Value interface{} `json:"value"`
Expand Down Expand Up @@ -283,7 +308,7 @@ func (s *TasksService) CreateTask(ctx context.Context, listID string, tr *TaskRe
}

// FIXME: assignees add/rem
func (s *TasksService) UpdateTask(ctx context.Context, taskID string, opts *GetTaskOptions, tr *TaskRequest) (*Task, *Response, error) {
func (s *TasksService) UpdateTask(ctx context.Context, taskID string, opts *GetTaskOptions, tr *TaskUpdateRequest) (*Task, *Response, error) {
u := fmt.Sprintf("task/%v/", taskID)
u, err := addOptions(u, opts)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions example/update-duedate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func main() {
getTask(ctx, client, taskId)

fmt.Println("\nUpdate due date of the task to 2122/01/02 03:04:05:06")
updateTask(ctx, client, taskId, &clickup.TaskRequest{
updateTask(ctx, client, taskId, &clickup.TaskUpdateRequest{
DueDate: clickup.NewDate(
time.Date(2122, 1, 2, 3, 4, 5, 6, time.Now().Location()),
),
})

fmt.Println("\nUpdate the task with empty TaskRequest")
updateTask(ctx, client, taskId, &clickup.TaskRequest{})
updateTask(ctx, client, taskId, &clickup.TaskUpdateRequest{})

fmt.Println("\nRemove task due date with NullDate()")
updateTask(ctx, client, taskId, &clickup.TaskRequest{
updateTask(ctx, client, taskId, &clickup.TaskUpdateRequest{
DueDate: clickup.NullDate(),
})
}
Expand All @@ -50,7 +50,7 @@ func getTask(ctx context.Context, client *clickup.Client, taskID string) {
fmt.Println(task.Name, task.DueDate)
}

func updateTask(ctx context.Context, client *clickup.Client, taskID string, tr *clickup.TaskRequest) {
func updateTask(ctx context.Context, client *clickup.Client, taskID string, tr *clickup.TaskUpdateRequest) {
task, _, err := client.Tasks.UpdateTask(ctx, taskID, &clickup.GetTaskOptions{}, tr)
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit ac90cf7

Please sign in to comment.