[FIX/BE-US] add transfer to laying filter location and area

This commit is contained in:
ragilap
2026-01-27 22:28:14 +07:00
parent 8848a50e3b
commit 8410573ee6
2 changed files with 28 additions and 5 deletions
@@ -52,6 +52,8 @@ type GetAllFilterParams struct {
FlockSource []uint
FlockDestination []uint
Status []string
LocationIDs []uint
LocationRestrict bool
}
func (r *TransferLayingRepositoryImpl) GetAllWithFilters(ctx context.Context, offset int, limit int, params *GetAllFilterParams) ([]entity.LayingTransfer, int64, error) {
@@ -110,6 +112,25 @@ func (r *TransferLayingRepositoryImpl) GetAllWithFilters(ctx context.Context, of
}
}
if params.LocationRestrict {
if len(params.LocationIDs) == 0 {
q = q.Where("1 = 0")
} else {
q = q.Where(
`EXISTS (
SELECT 1 FROM project_flocks pf
WHERE pf.id = laying_transfers.from_project_flock_id
AND pf.location_id IN ?
) OR EXISTS (
SELECT 1 FROM project_flocks pf
WHERE pf.id = laying_transfers.to_project_flock_id
AND pf.location_id IN ?
)`,
params.LocationIDs, params.LocationIDs,
)
}
}
if err := q.Count(&total).Error; err != nil {
return nil, 0, err
}