feat(cart): Line items operations (#6066)

This commit is contained in:
Oli Juhl
2024-01-16 15:44:49 +01:00
committed by GitHub
parent 6315a61189
commit a5e8bf06c6
18 changed files with 973 additions and 136 deletions
+20 -2
View File
@@ -336,6 +336,16 @@ export interface CartLineItemDTO {
* @expandable
*/
adjustments?: LineItemAdjustmentLineDTO[]
/**
* The associated cart.
*
* @expandable
*/
cart: CartDTO
/**
* The ID of the associated cart.
*/
cart_id: string
/**
* Holds custom data in key-value pairs.
*/
@@ -470,12 +480,20 @@ export interface FilterableAddressProps
id?: string | string[]
}
export interface FilterableLineItemProps
extends BaseFilterable<FilterableLineItemProps> {
id?: string | string[]
cart_id?: string | string[]
title?: string
variant_id?: string | string[]
product_id?: string | string[]
}
/**
* TODO: Remove this in favor of CartDTO, when module is released
* @deprecated Use CartDTO instead
*/
export type legacy__CartDTO = {
export type legacy_CartDTO = {
id?: string
email?: string
billing_address_id?: string
+24 -14
View File
@@ -1,3 +1,5 @@
import { CartLineItemDTO } from "./common"
export interface UpsertAddressDTO {
customer_id?: string
company?: string
@@ -93,6 +95,8 @@ export interface CreateLineItemDTO {
subtitle?: string
thumbnail?: string
cart_id?: string
quantity: number
product_id?: string
@@ -116,24 +120,30 @@ export interface CreateLineItemDTO {
compare_at_unit_price?: number
unit_price: number
tax_lines: CreateLineItemTaxLineDTO[]
adjustments: CreateLineItemAdjustmentDTO[]
tax_lines?: CreateLineItemTaxLineDTO[]
adjustments?: CreateLineItemAdjustmentDTO[]
}
export interface CreateLineItemForCartDTO extends CreateLineItemDTO {
cart_id: string
}
export interface UpdateLineItemWithSelectorDTO {
selector: Partial<CartLineItemDTO>
data: Partial<UpdateLineItemDTO>
}
export interface UpdateLineItemDTO
extends Omit<CreateLineItemDTO, "tax_lines" | "adjustments"> {
extends Omit<
CreateLineItemDTO,
"tax_lines" | "adjustments" | "title" | "quantity" | "unit_price"
> {
id: string
tax_lines: UpdateLineItemTaxLineDTO[] | CreateLineItemTaxLineDTO[]
adjustments: UpdateLineItemAdjustmentDTO[] | CreateLineItemAdjustmentDTO[]
}
title?: string
quantity?: number
unit_price?: number
export interface AddLineItemsDTO {
cart_id: string
items: CreateLineItemDTO[]
}
export interface UpdateLineItemsDTO {
cart_id: string
items: UpdateLineItemDTO[]
tax_lines?: UpdateLineItemTaxLineDTO[] | CreateLineItemTaxLineDTO[]
adjustments?: UpdateLineItemAdjustmentDTO[] | CreateLineItemAdjustmentDTO[]
}
+38 -17
View File
@@ -1,13 +1,22 @@
import { AddressDTO } from "../address"
import { FindConfig } from "../common"
import { IModuleService } from "../modules-sdk"
import { Context } from "../shared-context"
import { CartAddressDTO, CartDTO, FilterableAddressProps, FilterableCartProps } from "./common"
import {
CartAddressDTO,
CartDTO,
CartLineItemDTO,
FilterableAddressProps,
FilterableCartProps,
} from "./common"
import {
CreateAddressDTO,
CreateCartDTO,
CreateLineItemDTO,
CreateLineItemForCartDTO,
UpdateAddressDTO,
UpdateCartDTO,
UpdateLineItemDTO,
UpdateLineItemWithSelectorDTO,
} from "./mutations"
export interface ICartModuleService extends IModuleService {
@@ -40,7 +49,7 @@ export interface ICartModuleService extends IModuleService {
listAddresses(
filters?: FilterableAddressProps,
config?: FindConfig<AddressDTO>,
config?: FindConfig<CartAddressDTO>,
sharedContext?: Context
): Promise<CartAddressDTO[]>
@@ -65,20 +74,32 @@ export interface ICartModuleService extends IModuleService {
deleteAddresses(ids: string[], sharedContext?: Context): Promise<void>
deleteAddresses(ids: string, sharedContext?: Context): Promise<void>
// addLineItems(data: AddLineItemsDTO, sharedContext?: Context): Promise<CartDTO>
// addLineItems(
// data: AddLineItemsDTO[],
// sharedContext?: Context
// ): Promise<CartDTO[]>
addLineItems(data: CreateLineItemForCartDTO): Promise<CartLineItemDTO>
addLineItems(data: CreateLineItemForCartDTO[]): Promise<CartLineItemDTO[]>
addLineItems(
cartId: string,
items: CreateLineItemDTO[],
sharedContext?: Context
): Promise<CartLineItemDTO[]>
// updateLineItems(
// data: UpdateLineItemsDTO,
// sharedContext?: Context
// ): Promise<CartDTO>
// updateLineItems(
// data: UpdateLineItemsDTO[],
// sharedContext?: Context
// ): Promise<CartDTO[]>
updateLineItems(
data: UpdateLineItemWithSelectorDTO[]
): Promise<CartLineItemDTO[]>
updateLineItems(
selector: Partial<CartLineItemDTO>,
data: Partial<UpdateLineItemDTO>,
sharedContext?: Context
): Promise<CartLineItemDTO[]>
updateLineItems(
lineId: string,
data: Partial<UpdateLineItemDTO>,
sharedContext?: Context
): Promise<CartLineItemDTO>
// removeLineItems(lineItemIds: string[], sharedContext?: Context): Promise<void>
removeLineItems(itemIds: string[], sharedContext?: Context): Promise<void>
removeLineItems(itemIds: string, sharedContext?: Context): Promise<void>
removeLineItems(
selector: Partial<CartLineItemDTO>,
sharedContext?: Context
): Promise<void>
}