Skip to content

Commit

Permalink
moved FilterMtoShipments to mto_shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
JonSpight committed Feb 28, 2025
1 parent f922aef commit fe99d08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
22 changes: 22 additions & 0 deletions pkg/models/mto_shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,25 @@ func FetchShipmentByID(db *pop.Connection, shipmentID uuid.UUID) (*MTOShipment,
}
return &mtoShipment, nil
}

// filters the returned MtoShipments for each move.
// Ignoring mto shipments that have been deleted, cancelled, rejected, or cancelled requested.
func FilterMtoShipments(unfilteredShipments MTOShipments) MTOShipments {
//filter
if len(unfilteredShipments) == 0 {
return unfilteredShipments
}

filteredShipments := MTOShipments{}
for _, shipment := range unfilteredShipments {
if shipment.DeletedAt == nil &&
(shipment.Status != MTOShipmentStatusDraft) &&
(shipment.Status != MTOShipmentStatusRejected) &&
(shipment.Status != MTOShipmentStatusCancellationRequested) &&
(shipment.Status != MTOShipmentStatusCanceled) {
filteredShipments = append(filteredShipments, shipment)
}
}

return filteredShipments
}
42 changes: 21 additions & 21 deletions pkg/services/move/move_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s moveSearcher) SearchMoves(appCtx appcontext.AppContext, params *services

for i := range moves {
if moves[i].MTOShipments != nil {
moves[i].MTOShipments = filterMtoShipments(moves[i].MTOShipments)
moves[i].MTOShipments = models.FilterMtoShipments(moves[i].MTOShipments)
}
}
return moves, query.Paginator.TotalEntriesSize, nil
Expand Down Expand Up @@ -244,23 +244,23 @@ func orderName(query *pop.Query, order *string) *pop.Query {
}

// filters the returned MtoShipments for each move.
// Ignoring mto shipments that have been deleted, cancelled, rejected, or cancelled requested.
func filterMtoShipments(unfilteredShipments models.MTOShipments) models.MTOShipments {
//filter
if len(unfilteredShipments) == 0 {
return unfilteredShipments
}

filteredShipments := models.MTOShipments{}
for _, shipment := range unfilteredShipments {
if shipment.DeletedAt == nil &&
(shipment.Status != models.MTOShipmentStatusDraft) &&
(shipment.Status != models.MTOShipmentStatusRejected) &&
(shipment.Status != models.MTOShipmentStatusCancellationRequested) &&
(shipment.Status != models.MTOShipmentStatusCanceled) { //append if deleted, or status = DRAFT, Rejected, cancelled
filteredShipments = append(filteredShipments, shipment)
}
}

return filteredShipments
}
// // Ignoring mto shipments that have been deleted, cancelled, rejected, or cancelled requested.
// func filterMtoShipments(unfilteredShipments models.MTOShipments) models.MTOShipments {
// //filter
// if len(unfilteredShipments) == 0 {
// return unfilteredShipments
// }

// filteredShipments := models.MTOShipments{}
// for _, shipment := range unfilteredShipments {
// if shipment.DeletedAt == nil &&
// (shipment.Status != models.MTOShipmentStatusDraft) &&
// (shipment.Status != models.MTOShipmentStatusRejected) &&
// (shipment.Status != models.MTOShipmentStatusCancellationRequested) &&
// (shipment.Status != models.MTOShipmentStatusCanceled) { //append if deleted, or status = DRAFT, Rejected, cancelled
// filteredShipments = append(filteredShipments, shipment)
// }
// }

// return filteredShipments
// }

0 comments on commit fe99d08

Please sign in to comment.