Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

fix: bug in updating a customer's phones and addresses #240

Merged
merged 1 commit into from
Oct 11, 2020
Merged

fix: bug in updating a customer's phones and addresses #240

merged 1 commit into from
Oct 11, 2020

Conversation

vxio
Copy link
Member

@vxio vxio commented Oct 9, 2020

Fixes #239 and a similar bug related to updating a customer's addresses

Calling PUT /customers/{id} should delete any customer phones or addresses not in the request body — or upsert the specified phone or address values.

@@ -486,6 +486,7 @@ func (r *sqlCustomerRepository) updateCustomer(c *client.Customer, organization
if err != nil {
return err
}
defer tx.Rollback()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tx.Rollback() was being called multiple times but it only needs to be called once in a defer since a rollback won't occur if the transaction is successfully commited.

Source: https://stackoverflow.com/questions/46421602/why-defer-a-rollback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. I didn't know Rollback checked if the transaction was successful or not.

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@ea53223). Click here to learn what that means.
The diff coverage is 67.56%.

@@            Coverage Diff            @@
##             master     #240   +/-   ##
=========================================
  Coverage          ?   58.57%           
=========================================
  Files             ?       52           
  Lines             ?     2911           
  Branches          ?        0           
=========================================
  Hits              ?     1705           
  Misses            ?      893           
  Partials          ?      313           

@vxio vxio merged commit c605024 into moov-io:master Oct 11, 2020
@alovak
Copy link
Contributor

alovak commented Oct 12, 2020

Interesting, that we update/delete phone by number which may be formatted in different way. Adding constraint to db based on customerID and phone number will not work for 100% of cases. As we have separate customers_phones table maybe we just should add endpoints to manage customer's phones by ID?

@adamdecaf
Copy link
Member

I think phone number normalization / validation would come in v0.6.x as part of the larger data validation issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customer phone numbers can not be deleted.
4 participants