diff --git a/api/task.go b/api/task.go
index 2fc84ce..73238e2 100644
--- a/api/task.go
+++ b/api/task.go
@@ -86,6 +86,24 @@ func Task(g *gin.RouterGroup, db database.Database) {
return nil, err
}
+ if update.ItemID != nil && *update.ItemID != task.ItemID {
+ _, err := l.FindItem(c.Request.Context(), *update.ItemID)
+ if err != nil {
+ return nil, err
+ }
+
+ logs, err := l.ListLogs(c.Request.Context(), models.LogFilter{
+ TaskIDs: []string{task.ID},
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ if len(logs) > 0 {
+ return nil, slerrors.Forbidden("You cannot change the item if the task has logs.")
+ }
+ }
+
task.Update(update)
if task.EndTime != nil && task.EndTime.Before(task.CreatedTime) {
return nil, slerrors.BadRequest("Task end time must be later than it was created.")
diff --git a/models/task.go b/models/task.go
index 7a00139..ea8c756 100644
--- a/models/task.go
+++ b/models/task.go
@@ -20,6 +20,9 @@ type Task struct {
}
func (task *Task) Update(update TaskUpdate) {
+ if update.ItemID != nil {
+ task.ItemID = *update.ItemID
+ }
if update.ItemAmount != nil {
task.ItemAmount = *update.ItemAmount
}
@@ -42,6 +45,7 @@ func (task *Task) Update(update TaskUpdate) {
}
type TaskUpdate struct {
+ ItemID *string `json:"itemId"`
ItemAmount *int `json:"itemAmount"`
Name *string `json:"name"`
Description *string `json:"description"`
diff --git a/svelte-ui/src/forms/TaskForm.svelte b/svelte-ui/src/forms/TaskForm.svelte
index 0371d33..ca7bc5e 100644
--- a/svelte-ui/src/forms/TaskForm.svelte
+++ b/svelte-ui/src/forms/TaskForm.svelte
@@ -86,7 +86,7 @@
clearEndTime: endTime == "",
active: !completed,
- name, description, itemAmount,
+ itemId, name, description, itemAmount,
}).then(() => {
markStale("goal", "project", "task");
modalStore.close();
@@ -108,7 +108,7 @@
-
+
diff --git a/svelte-ui/src/models/task.ts b/svelte-ui/src/models/task.ts
index bbd9490..dc69231 100644
--- a/svelte-ui/src/models/task.ts
+++ b/svelte-ui/src/models/task.ts
@@ -38,6 +38,7 @@ export interface TaskInput {
}
export interface TaskUpdate {
+ itemId?: string
itemAmount?: number
name?: string
description?: string