This commit is contained in:
+18
@@ -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.")
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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 @@
|
||||
<label for="description">Description</label>
|
||||
<textarea disabled={deletion} name="description" bind:value={description} />
|
||||
<label for="itemId">Item</label>
|
||||
<ItemSelect disabled={!creation} name="itemId" bind:value={itemId} />
|
||||
<ItemSelect disabled={deletion} name="itemId" bind:value={itemId} />
|
||||
<label for="itemAmount">Amount</label>
|
||||
<input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} />
|
||||
<label for="endTime">Deadline (Optional)</label>
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface TaskInput {
|
||||
}
|
||||
|
||||
export interface TaskUpdate {
|
||||
itemId?: string
|
||||
itemAmount?: number
|
||||
name?: string
|
||||
description?: string
|
||||
|
||||
Reference in New Issue
Block a user