feat(profile): align chatwoot user serializer
This commit is contained in:
@@ -30,14 +30,15 @@ func (h *ProfileHandler) Get(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := h.svc.Get(c.Request.Context(), userID)
|
||||
accountID := c.GetUint("account_id")
|
||||
user, err := h.svc.Get(c.Request.Context(), userID, accountID)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Get profile for user %d: %v", userID, err)
|
||||
handleServiceError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// Update updates the current user's profile.
|
||||
@@ -55,14 +56,15 @@ func (h *ProfileHandler) Update(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, svcErr := h.svc.Update(c.Request.Context(), userID, req.Profile)
|
||||
accountID := c.GetUint("account_id")
|
||||
user, svcErr := h.svc.Update(c.Request.Context(), userID, accountID, req.Profile)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("Update profile for user %d: %v", userID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// UpdateAvatar updates the current user's avatar.
|
||||
@@ -80,14 +82,15 @@ func (h *ProfileHandler) UpdateAvatar(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, svcErr := h.svc.UpdateAvatar(c.Request.Context(), userID, req)
|
||||
accountID := c.GetUint("account_id")
|
||||
user, svcErr := h.svc.UpdateAvatar(c.Request.Context(), userID, accountID, req)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("Update avatar for user %d: %v", userID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// SetAvailability updates the user's availability status for a specific account.
|
||||
@@ -106,14 +109,14 @@ func (h *ProfileHandler) SetAvailability(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
au, svcErr := h.svc.SetAvailability(c.Request.Context(), userID, req.Profile)
|
||||
user, svcErr := h.svc.SetAvailability(c.Request.Context(), userID, req.Profile)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("SetAvailability for user %d: %v", userID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, au)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// SetAutoOffline updates the user's auto_offline setting for a specific account.
|
||||
@@ -132,14 +135,14 @@ func (h *ProfileHandler) SetAutoOffline(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
au, svcErr := h.svc.SetAutoOffline(c.Request.Context(), userID, req.Profile)
|
||||
user, svcErr := h.svc.SetAutoOffline(c.Request.Context(), userID, req.Profile)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("SetAutoOffline for user %d: %v", userID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, au)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// SetActiveAccount sets the user's currently active account.
|
||||
@@ -198,14 +201,15 @@ func (h *ProfileHandler) ResetAccessToken(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, svcErr := h.svc.ResetAccessToken(c.Request.Context(), userID)
|
||||
accountID := c.GetUint("account_id")
|
||||
user, svcErr := h.svc.ResetAccessToken(c.Request.Context(), userID, accountID)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("ResetAccessToken for user %d: %v", userID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, user)
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
// DeleteAvatar removes the user's avatar.
|
||||
@@ -217,11 +221,12 @@ func (h *ProfileHandler) DeleteAvatar(c *gin.Context) {
|
||||
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "user not authenticated")
|
||||
return
|
||||
}
|
||||
user, err := h.svc.DeleteAvatar(c.Request.Context(), userID)
|
||||
accountID := c.GetUint("account_id")
|
||||
user, err := h.svc.DeleteAvatar(c.Request.Context(), userID, accountID)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("DeleteAvatar for user %d: %v", userID, err)
|
||||
handleServiceError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, user)
|
||||
}
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user