Add validation to deleteThing endpoint to prevent deletion of things with associated tasks
This commit is contained in:
parent
e40c2a84cd
commit
6845fd54f1
|
@ -48,6 +48,9 @@ func (n *NotificationPlanner) GenerateNotifications(c context.Context, chore *ch
|
||||||
var mt *chModel.NotificationMetadata
|
var mt *chModel.NotificationMetadata
|
||||||
if err := json.Unmarshal([]byte(*chore.NotificationMetadata), &mt); err != nil {
|
if err := json.Unmarshal([]byte(*chore.NotificationMetadata), &mt); err != nil {
|
||||||
log.Error("Error unmarshalling notification metadata", err)
|
log.Error("Error unmarshalling notification metadata", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if chore.NextDueDate == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if mt.DueDate {
|
if mt.DueDate {
|
||||||
|
|
|
@ -261,6 +261,16 @@ func (h *Handler) DeleteThing(c *gin.Context) {
|
||||||
c.JSON(403, gin.H{"error": "Forbidden"})
|
c.JSON(403, gin.H{"error": "Forbidden"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// confirm there are no chores associated with the thing:
|
||||||
|
thingChores, err := h.tRepo.GetThingChoresByThingId(c, thing.ID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(500, gin.H{"error": "Unable to find tasks linked to this thing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(thingChores) > 0 {
|
||||||
|
c.JSON(405, gin.H{"error": "Unable to delete thing with associated tasks"})
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := h.tRepo.DeleteThing(c, thingID); err != nil {
|
if err := h.tRepo.DeleteThing(c, thingID); err != nil {
|
||||||
c.JSON(500, gin.H{"error": err.Error()})
|
c.JSON(500, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue