Skip to content

Commit

Permalink
rolling this rate stuff back.. please stop breaking erverything
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstanceH committed Jan 15, 2025
1 parent f8baaa5 commit 39bf1c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/models/re_rate_area.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func FetchReRateAreaItem(tx *pop.Connection, contractID uuid.UUID, code string)
}

// a db stored proc that takes in an address id & a service code to get the rate area id for an address
func FetchRateAreaID(db *pop.Connection, addressID uuid.UUID, serviceID uuid.UUID, contractID uuid.UUID) (uuid.UUID, error) {
func FetchRateAreaID(db *pop.Connection, addressID uuid.UUID, serviceID *uuid.UUID, contractID uuid.UUID) (uuid.UUID, error) {
if addressID != uuid.Nil && contractID != uuid.Nil {
var rateAreaID uuid.UUID
err := db.RawQuery("SELECT get_rate_area_id($1, $2, $3)", addressID, serviceID, contractID).First(&rateAreaID)
Expand Down
6 changes: 2 additions & 4 deletions pkg/models/re_rate_area_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ func (suite *ModelSuite) TestFetchRateAreaID() {
service := factory.FetchReServiceByCode(suite.DB(), models.ReServiceCodeIHPK)
contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{})
address := factory.BuildAddress(suite.DB(), nil, nil)
rateAreaId, err := models.FetchRateAreaID(suite.DB(), address.ID, service.ID, contract.ID)
rateAreaId, err := models.FetchRateAreaID(suite.DB(), address.ID, &service.ID, contract.ID)
suite.NotNil(rateAreaId)
suite.NoError(err)
})

suite.Run("fail - receive error when not all values are provided", func() {
var nilUuid uuid.UUID
contract := testdatagen.FetchOrMakeReContract(suite.DB(), testdatagen.Assertions{})
address := factory.BuildAddress(suite.DB(), nil, nil)
rateAreaId, err := models.FetchRateAreaID(suite.DB(), address.ID, nilUuid, contract.ID)
rateAreaId, err := models.FetchRateAreaID(suite.DB(), address.ID, nil, uuid.Nil)
suite.Equal(uuid.Nil, rateAreaId)
suite.Error(err)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (p PerUnitCentsLookup) lookup(appCtx appcontext.AppContext, s *ServiceItemP
switch p.ServiceItem.ReService.Code {
case models.ReServiceCodeIHPK:
// IHPK: Need rate area ID for the pickup address
rateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, serviceID, contractID)
rateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, &serviceID, contractID)
if err != nil {
return "", fmt.Errorf("error fetching rate area id for shipment ID: %s and service ID %s: %s", p.MTOShipment.ID, serviceID, err)
}
Expand All @@ -43,7 +43,7 @@ func (p PerUnitCentsLookup) lookup(appCtx appcontext.AppContext, s *ServiceItemP

case models.ReServiceCodeIHUPK:
// IHUPK: Need rate area ID for the destination address
rateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, serviceID, contractID)
rateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, &serviceID, contractID)
if err != nil {
return "", fmt.Errorf("error fetching rate area id for shipment ID: %s and service ID %s: %s", p.MTOShipment.ID, serviceID, err)
}
Expand All @@ -62,11 +62,11 @@ func (p PerUnitCentsLookup) lookup(appCtx appcontext.AppContext, s *ServiceItemP

case models.ReServiceCodeISLH:
// ISLH: Need rate area IDs for origin and destination
originRateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, serviceID, contractID)
originRateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.PickupAddressID, &serviceID, contractID)
if err != nil {
return "", fmt.Errorf("error fetching rate area id for origin address for shipment ID: %s and service ID %s: %s", p.MTOShipment.ID, serviceID, err)
}
destRateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.DestinationAddressID, serviceID, contractID)
destRateAreaID, err := models.FetchRateAreaID(appCtx.DB(), *p.MTOShipment.DestinationAddressID, &serviceID, contractID)
if err != nil {
return "", fmt.Errorf("error fetching rate area id for destination address for shipment ID: %s and service ID %s: %s", p.MTOShipment.ID, serviceID, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (f *shipmentAddressUpdateRequester) doesDeliveryAddressUpdateChangeServiceO
// international shipments find their rate areas differently than domestic
if shipment.MarketCode == models.MarketCodeInternational {
// we already have the origin address in the db so we can check the rate area using the db func
originalRateArea, err := models.FetchRateAreaID(appCtx.DB(), originalDeliveryAddress.ID, uuid.Nil, contractID)
originalRateArea, err := models.FetchRateAreaID(appCtx.DB(), originalDeliveryAddress.ID, nil, contractID)
if err != nil || originalRateArea == uuid.Nil {
return false, err
}
Expand Down

0 comments on commit 39bf1c8

Please sign in to comment.