Skip to content

Commit

Permalink
Merge pull request #398 from factly/refactor/admin-users
Browse files Browse the repository at this point in the history
refactor user responses
  • Loading branch information
shreeharsha-factly authored Aug 3, 2023
2 parents 2bf9b49 + 3f0d9e1 commit d2ad510
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 0 additions & 1 deletion server/action/admin/organisation/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ func list(w http.ResponseWriter, r *http.Request) {
}

renderx.JSON(w, http.StatusOK, res)
return
}
7 changes: 3 additions & 4 deletions server/action/admin/user/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type response struct {
Nodes []model.User `json:"node"`
Nodes []model.User `json:"nodes"`
Total int64 `json:"total"`
}

Expand All @@ -22,14 +22,14 @@ func list(w http.ResponseWriter, r *http.Request) {

if len(userIDs) == 0 {
offset, limit := paginationx.Parse(r.URL.Query())
err := model.DB.Model(&model.User{}).Count(&res.Total).Offset(offset).Limit(limit).Preload("Organisations").Find(&res.Nodes).Error
err := model.DB.Model(&model.User{}).Count(&res.Total).Offset(offset).Limit(limit).Find(&res.Nodes).Error
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.DBError()))
return
}
} else {
err := model.DB.Model(&model.User{}).Where(userIDs).Preload("Organisations").Find(&res.Nodes).Error
err := model.DB.Model(&model.User{}).Where(userIDs).Find(&res.Nodes).Error
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.DBError()))
Expand All @@ -40,5 +40,4 @@ func list(w http.ResponseWriter, r *http.Request) {
}

renderx.JSON(w, http.StatusOK, res)
return
}

0 comments on commit d2ad510

Please sign in to comment.