feat (infra): add filter data that only have children
This commit is contained in:
@@ -21,10 +21,11 @@ type CreateDto struct {
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Preloads []string `json:"-"`
|
||||
Search string `json:"search"`
|
||||
Pagination ecore.Pagination
|
||||
Includes string `json:"includes"`
|
||||
Preloads []string `json:"-"`
|
||||
Search string `json:"search"`
|
||||
Pagination ecore.Pagination
|
||||
OnlyHaveChildren bool `json:"only-have-children"`
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
|
||||
@@ -55,6 +55,16 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
|
||||
|
||||
plh.SearchCodeOrName(input.Search, tx)
|
||||
|
||||
if input.OnlyHaveChildren {
|
||||
tx = tx.Where(`
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM "Infra" c
|
||||
WHERE c."Parent_Id" = "Infra"."Id"
|
||||
)
|
||||
`)
|
||||
}
|
||||
|
||||
tx = tx.
|
||||
Model(&e.Infra{}).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
|
||||
Reference in New Issue
Block a user