feat(customer): add customer addresses (#6224)

**What**
- adds methods to create update list customer addresses
- removes default_shipping_id and billing id from customer record and moves them to address (better normalization)
This commit is contained in:
Sebastian Rindom
2024-01-26 15:35:23 +00:00
committed by GitHub
parent 638b47ff70
commit 8c6cc82c5d
9 changed files with 672 additions and 112 deletions
+46 -4
View File
@@ -1,6 +1,50 @@
import { AddressDTO } from "../address"
import { BaseFilterable } from "../dal"
import { OperatorMap } from "../dal/utils"
import { AddressDTO } from "../address"
export interface CustomerAddressDTO {
id: string
address_name?: string
is_default_shipping: boolean
is_default_billing: boolean
customer_id: string
company?: string
first_name?: string
last_name?: string
address_1?: string
address_2?: string
city?: string
country_code?: string
province?: string
postal_code?: string
phone?: string
metadata?: Record<string, unknown>
created_at: string
updated_at: string
}
export interface FilterableCustomerAddressProps
extends BaseFilterable<FilterableCustomerAddressProps> {
id?: string | string[]
address_name?: string | OperatorMap<string>
is_default_shipping?: boolean | OperatorMap<boolean>
is_default_billing?: boolean | OperatorMap<boolean>
customer_id?: string | string[]
customer?: FilterableCustomerProps | string | string[]
company?: string | OperatorMap<string>
first_name?: string | OperatorMap<string>
last_name?: string | OperatorMap<string>
address_1?: string | OperatorMap<string>
address_2?: string | OperatorMap<string>
city?: string | OperatorMap<string>
country_code?: string | OperatorMap<string>
province?: string | OperatorMap<string>
postal_code?: string | OperatorMap<string>
phone?: string | OperatorMap<string>
metadata?: Record<string, unknown> | OperatorMap<Record<string, unknown>>
created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
}
export interface FilterableCustomerGroupProps
extends BaseFilterable<FilterableCustomerGroupProps> {
@@ -69,9 +113,7 @@ export interface CustomerDTO {
company_name?: string | null
first_name?: string | null
last_name?: string | null
default_billing_address?: AddressDTO
default_shipping_address?: AddressDTO
addresses?: AddressDTO[]
addresses?: CustomerAddressDTO[]
phone?: string | null
groups?: { id: string }[]
metadata?: Record<string, unknown>
+38
View File
@@ -1,3 +1,40 @@
export interface CreateCustomerAddressDTO {
address_name?: string
is_default_shipping?: boolean
is_default_billing?: boolean
customer_id: string
company?: string
first_name?: string
last_name?: string
address_1?: string
address_2?: string
city?: string
country_code?: string
province?: string
postal_code?: string
phone?: string
metadata?: Record<string, unknown>
}
export interface UpdateCustomerAddressDTO {
id?: string
address_name?: string
is_default_shipping?: boolean
is_default_billing?: boolean
customer_id?: string
company?: string
first_name?: string
last_name?: string
address_1?: string
address_2?: string
city?: string
country_code?: string
province?: string
postal_code?: string
phone?: string
metadata?: Record<string, unknown>
}
export interface CreateCustomerDTO {
company_name?: string
first_name?: string
@@ -5,6 +42,7 @@ export interface CreateCustomerDTO {
email?: string
phone?: string
created_by?: string
addresses?: Omit<CreateCustomerAddressDTO, "customer_id">[]
metadata?: Record<string, unknown>
}
+39 -1
View File
@@ -10,8 +10,15 @@ import {
FilterableCustomerProps,
FilterableCustomerGroupProps,
GroupCustomerPair,
FilterableCustomerAddressProps,
CustomerAddressDTO,
} from "./common"
import { CreateCustomerDTO, CreateCustomerGroupDTO } from "./mutations"
import {
CreateCustomerAddressDTO,
CreateCustomerDTO,
CreateCustomerGroupDTO,
UpdateCustomerAddressDTO,
} from "./mutations"
export interface ICustomerModuleService extends IModuleService {
retrieve(
@@ -110,6 +117,37 @@ export interface ICustomerModuleService extends IModuleService {
sharedContext?: Context
): Promise<void>
addAddresses(
addresses: CreateCustomerAddressDTO[],
sharedContext?: Context
): Promise<CustomerAddressDTO[]>
addAddresses(
address: CreateCustomerAddressDTO,
sharedContext?: Context
): Promise<CustomerAddressDTO>
updateAddress(
addressId: string,
data: UpdateCustomerAddressDTO,
sharedContext?: Context
): Promise<CustomerAddressDTO>
updateAddress(
addressIds: string[],
data: UpdateCustomerAddressDTO,
sharedContext?: Context
): Promise<CustomerAddressDTO[]>
updateAddress(
selector: FilterableCustomerAddressProps,
data: UpdateCustomerAddressDTO,
sharedContext?: Context
): Promise<CustomerAddressDTO[]>
listAddresses(
filters?: FilterableCustomerAddressProps,
config?: FindConfig<CustomerAddressDTO>,
sharedContext?: Context
): Promise<CustomerAddressDTO[]>
listCustomerGroupRelations(
filters?: FilterableCustomerGroupCustomerProps,
config?: FindConfig<CustomerGroupCustomerDTO>,