feat(customer): manage default address selection (#6295)

**What**
- Catches unique constraints on customer_id, is_default_billing/is_default_shipping and reformats
- Adds an step to create and update of addresses that unsets the previous default shipping/billing address if necessary.
  - This creates a behavior in the API where you can always set an address to be default and it will automatically unset the previous one for you.
This commit is contained in:
Sebastian Rindom
2024-02-01 13:28:14 +01:00
committed by GitHub
parent a28822e0d4
commit a2bf6756ac
16 changed files with 506 additions and 15 deletions

View File

@@ -0,0 +1,2 @@
export * from "./postgres-error"
export * from "./is-duplicate-error"

View File

@@ -0,0 +1,4 @@
import { PostgresError } from "./postgres-error"
export const isDuplicateError = (err: Error & { code?: string }) => {
return err.code === PostgresError.DUPLICATE_ERROR
}

View File

@@ -0,0 +1,6 @@
export enum PostgresError {
DUPLICATE_ERROR = "23505",
FOREIGN_KEY_ERROR = "23503",
SERIALIZATION_FAILURE = "40001",
NULL_VIOLATION = "23502",
}