Browse Source

fix task validation to not allow end time before created time, and disallow <=0 amounts.

main
Gisle Aune 4 years ago
parent
commit
2664c47dff
  1. 15
      api/task.go
  2. 4
      svelte-ui/src/components/LogEntry.svelte
  3. 2
      svelte-ui/src/forms/TaskAddForm.svelte
  4. 2
      svelte-ui/src/forms/TaskEditForm.svelte

15
api/task.go

@ -33,13 +33,17 @@ func Task(g *gin.RouterGroup, db database.Database) {
}))
g.POST("/", handler("task", func(c *gin.Context) (interface{}, error) {
createdTime := time.Now()
task := models.Task{}
err := c.BindJSON(&task)
if err != nil {
return nil, slerrors.BadRequest("Invalid JSON")
}
if task.EndTime != nil && task.EndTime.Before(time.Now()) {
return nil, slerrors.BadRequest("Project end time must be later than current time.")
if task.EndTime != nil && task.EndTime.Before(createdTime) {
return nil, slerrors.BadRequest("Task end time must be later than current time.")
}
if task.ItemAmount <= 0 {
return nil, slerrors.BadRequest("Item amount cannot be zero or negative.")
}
project, err := l.FindProject(c.Request.Context(), task.ProjectID)
@ -83,6 +87,13 @@ func Task(g *gin.RouterGroup, db database.Database) {
}
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.")
}
if task.ItemAmount <= 0 {
return nil, slerrors.BadRequest("Item amount cannot be zero or negative.")
}
err = db.Tasks().Update(c.Request.Context(), task.Task)
if err != nil {
return nil, err

4
svelte-ui/src/components/LogEntry.svelte

@ -10,10 +10,12 @@
export let log: LogResult = null;
let taskIconName: IconName = "question";
let itemIconName: IconName = "question";
let mdLogEdit: ModalData;
let mdLogDelete: ModalData;
$: taskIconName = log.task.icon as IconName;
$: itemIconName = log.item.icon as IconName;
$: mdLogEdit = {name: "log.edit", log};
$: mdLogDelete = {name: "log.delete", log};
</script>
@ -31,7 +33,7 @@
<p>{log.description}</p>
<div class="item">
<div class="item-icon">
<Icon name={log.item.icon} />
<Icon name={itemIconName} />
</div>
<div class="item-name">{log.item.name} ({log.item.groupWeight})</div>
</div>

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

@ -26,6 +26,8 @@
projectStore.markStale();
fpProjectStore.markStale();
modalStore.close();
}).catch(err => {
error = err.message ? err.message : err.toString();
})
error = null;

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

@ -33,6 +33,8 @@ import Checkbox from "../components/Checkbox.svelte";
goalStore.markStale();
fpGoalStore.markStale();
modalStore.close();
}).catch(err => {
error = err.message ? err.message : err.toString();
})
error = null;

Loading…
Cancel
Save