From c78340944ff781be79b2f2778477dbf188a1c984 Mon Sep 17 00:00:00 2001 From: shreeharsha-factly Date: Sun, 10 Mar 2024 00:43:08 +0530 Subject: [PATCH] server: preload organisations in user admin endpoint --- server/action/admin/user/list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/action/admin/user/list.go b/server/action/admin/user/list.go index 8e2f47ca..273bb59b 100644 --- a/server/action/admin/user/list.go +++ b/server/action/admin/user/list.go @@ -29,14 +29,14 @@ func list(w http.ResponseWriter, r *http.Request) { if len(userIDs) == 0 { qs := "%" + searchQuery + "%" offset, limit := paginationx.Parse(r.URL.Query()) - err := model.DB.Model(&model.User{}).Where("display_name ILIKE ? OR email ILIKE ?", qs, qs).Order("created_at " + sort).Count(&res.Total).Offset(offset).Limit(limit).Find(&res.Nodes).Error + err := model.DB.Model(&model.User{}).Preload("Organisations").Where("display_name ILIKE ? OR email ILIKE ?", qs, qs).Order("created_at " + sort).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).Find(&res.Nodes).Error + err := model.DB.Model(&model.User{}).Preload("Organisations").Where(userIDs).Find(&res.Nodes).Error if err != nil { loggerx.Error(err) errorx.Render(w, errorx.Parser(errorx.DBError()))