mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FIX/BE-US] add transfer to laying filter location and area
This commit is contained in:
+21
@@ -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
|
||||
}
|
||||
|
||||
@@ -107,6 +107,11 @@ func (s transferLayingService) GetAll(c *fiber.Ctx, params *validation.Query) ([
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
scope, err := m.ResolveLocationScope(c, s.Repository.DB())
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
|
||||
filterParams := &repository.GetAllFilterParams{
|
||||
@@ -116,6 +121,8 @@ func (s transferLayingService) GetAll(c *fiber.Ctx, params *validation.Query) ([
|
||||
FlockSource: params.FlockSource,
|
||||
FlockDestination: params.FlockDestination,
|
||||
Status: params.Status,
|
||||
LocationIDs: scope.IDs,
|
||||
LocationRestrict: scope.Restrict,
|
||||
}
|
||||
|
||||
transferLayings, total, err := s.Repository.GetAllWithFilters(c.Context(), offset, params.Limit, filterParams)
|
||||
@@ -124,11 +131,6 @@ func (s transferLayingService) GetAll(c *fiber.Ctx, params *validation.Query) ([
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get transferLayings: %+v", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
approvalRepo := commonRepo.NewApprovalRepository(s.Repository.DB())
|
||||
for i, transfer := range transferLayings {
|
||||
latestApproval, err := approvalRepo.LatestByTarget(c.Context(), string(utils.ApprovalWorkflowTransferToLaying), transfer.Id, func(db *gorm.DB) *gorm.DB {
|
||||
|
||||
Reference in New Issue
Block a user