Skip to content

Commit d6d7cdb

Browse files
committed
fix: environment list query issue
1 parent 392cac4 commit d6d7cdb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

api/cluster/environment.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/0xJacky/Nginx-UI/settings"
1111
"github.com/gin-gonic/gin"
1212
"github.com/spf13/cast"
13+
"gorm.io/gorm"
1314
"net/http"
1415
)
1516

@@ -28,12 +29,19 @@ func GetEnvironment(c *gin.Context) {
2829
}
2930

3031
func GetEnvironmentList(c *gin.Context) {
31-
cosy.Core[model.Environment](c).
32-
SetFussy("name").
33-
SetEqual("enabled").
34-
SetTransformer(func(m *model.Environment) any {
35-
return analytic.GetNode(m)
36-
}).PagingList()
32+
core := cosy.Core[model.Environment](c).
33+
SetFussy("name")
34+
35+
// fix for sqlite
36+
if c.Query("enabled") != "" {
37+
core.GormScope(func(tx *gorm.DB) *gorm.DB {
38+
return tx.Where("enabled = ?", cast.ToInt(cast.ToBool(c.Query("enabled"))))
39+
})
40+
}
41+
42+
core.SetTransformer(func(m *model.Environment) any {
43+
return analytic.GetNode(m)
44+
}).PagingList()
3745
}
3846

3947
func AddEnvironment(c *gin.Context) {

0 commit comments

Comments
 (0)