diff options
author | Mo Tarbin <mhed.t91@gmail.com> | 2024-08-10 14:28:24 -0400 |
---|---|---|
committer | Mo Tarbin <mhed.t91@gmail.com> | 2024-09-06 01:13:29 -0400 |
commit | 187078ffe8db564f5a34d90acd24116daae9e901 (patch) | |
tree | 5082e6bd0efef508b33135103efb91167f4269d7 /internal/chore | |
parent | bddb80b1349c517ceaeacb92f5f8be9f482f400a (diff) | |
download | donetick-187078ffe8db564f5a34d90acd24116daae9e901.tar.gz donetick-187078ffe8db564f5a34d90acd24116daae9e901.tar.bz2 donetick-187078ffe8db564f5a34d90acd24116daae9e901.zip |
update `updateAssignee` to retrieve the current user and use their ID as the `UpdatedBy` field.
Diffstat (limited to '')
-rw-r--r-- | internal/chore/handler.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/chore/handler.go b/internal/chore/handler.go index 01490cc..7ae97b0 100644 --- a/internal/chore/handler.go +++ b/internal/chore/handler.go @@ -594,6 +594,13 @@ func (h *Handler) deleteChore(c *gin.Context) { // } func (h *Handler) updateAssignee(c *gin.Context) { + currentUser, ok := auth.CurrentUser(c) + if !ok { + c.JSON(500, gin.H{ + "error": "Error getting current user", + }) + return + } rawID := c.Param("id") id, err := strconv.Atoi(rawID) if err != nil { @@ -603,8 +610,7 @@ func (h *Handler) updateAssignee(c *gin.Context) { return } type AssigneeReq struct { - AssignedTo int `json:"assignedTo" binding:"required"` - UpdatedBy int `json:"updatedBy" binding:"required"` + Assignee int `json:"assignee" binding:"required"` } var assigneeReq AssigneeReq @@ -626,7 +632,7 @@ func (h *Handler) updateAssignee(c *gin.Context) { assigneeFound := false for _, assignee := range chore.Assignees { - if assignee.UserID == assigneeReq.AssignedTo { + if assignee.UserID == assigneeReq.Assignee { assigneeFound = true break } @@ -638,8 +644,8 @@ func (h *Handler) updateAssignee(c *gin.Context) { return } - chore.UpdatedBy = assigneeReq.UpdatedBy - chore.AssignedTo = assigneeReq.AssignedTo + chore.UpdatedBy = currentUser.ID + chore.AssignedTo = assigneeReq.Assignee if err := h.choreRepo.UpsertChore(c, chore); err != nil { c.JSON(500, gin.H{ "error": "Error updating assignee", |