Browse Source

allow changing item on tasks with logs.

main
Gisle Aune 4 years ago
parent
commit
2c5d87134d
  1. 18
      api/task.go
  2. 5
      database/postgres/tasks.go
  3. 2
      svelte-ui/src/forms/TaskForm.svelte

18
api/task.go

@ -86,24 +86,6 @@ func Task(g *gin.RouterGroup, db database.Database) {
return nil, err 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.")
}
}
if update.ProjectID != nil && *update.ProjectID != task.ProjectID { if update.ProjectID != nil && *update.ProjectID != task.ProjectID {
project, err := l.FindProject(c.Request.Context(), *update.ProjectID) project, err := l.FindProject(c.Request.Context(), *update.ProjectID)
if err != nil { if err != nil {

5
database/postgres/tasks.go

@ -102,6 +102,11 @@ func (r *taskRepository) Update(ctx context.Context, task models.Task) error {
return err return err
} }
_, err = r.db.NamedExecContext(ctx, `UPDATE log SET item_id = :item_id WHERE task_id=:task_id`, &task)
if err != nil {
return err
}
return nil return nil
} }

2
svelte-ui/src/forms/TaskForm.svelte

@ -117,7 +117,7 @@ import ProjectSelect from "../components/ProjectSelect.svelte";
<label for="description">Description</label> <label for="description">Description</label>
<textarea disabled={deletion} name="description" bind:value={description} /> <textarea disabled={deletion} name="description" bind:value={description} />
<label for="itemId">Item</label> <label for="itemId">Item</label>
<ItemSelect disabled={deletion || task.logs.length > 0} name="itemId" bind:value={itemId} />
<ItemSelect disabled={deletion} name="itemId" bind:value={itemId} />
<label for="itemAmount">Amount</label> <label for="itemAmount">Amount</label>
<input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} /> <input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} />
<label for="endTime">Deadline (Optional)</label> <label for="endTime">Deadline (Optional)</label>

Loading…
Cancel
Save