chore(cart): Use module native soft-delete/delete methods (#6491)
This commit is contained in:
@@ -2,7 +2,6 @@ import {
|
||||
CartTypes,
|
||||
Context,
|
||||
DAL,
|
||||
FilterableLineItemTaxLineProps,
|
||||
ICartModuleService,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
@@ -419,40 +418,6 @@ export default class CartModuleService<
|
||||
return await this.lineItemService_.update(toUpdate, sharedContext)
|
||||
}
|
||||
|
||||
async removeLineItems(
|
||||
itemIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeLineItems(itemIds: string, sharedContext?: Context): Promise<void>
|
||||
async removeLineItems(
|
||||
selector: Partial<CartTypes.CartLineItemDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async removeLineItems(
|
||||
itemIdsOrSelector: string | string[] | Partial<CartTypes.CartLineItemDTO>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let toDelete: string[]
|
||||
|
||||
if (isObject(itemIdsOrSelector)) {
|
||||
const items = await this.listLineItems(
|
||||
{ ...itemIdsOrSelector } as Partial<CartTypes.CartLineItemDTO>,
|
||||
{},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
toDelete = items.map((item) => item.id)
|
||||
} else {
|
||||
toDelete = Array.isArray(itemIdsOrSelector)
|
||||
? itemIdsOrSelector
|
||||
: [itemIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemService_.softDelete(toDelete, sharedContext)
|
||||
}
|
||||
|
||||
async createAddresses(
|
||||
data: CartTypes.CreateAddressDTO,
|
||||
sharedContext?: Context
|
||||
@@ -599,46 +564,6 @@ export default class CartModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
async removeShippingMethods(
|
||||
methodIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeShippingMethods(
|
||||
methodIds: string,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeShippingMethods(
|
||||
selector: Partial<CartTypes.CartShippingMethodDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async removeShippingMethods(
|
||||
methodIdsOrSelector:
|
||||
| string
|
||||
| string[]
|
||||
| Partial<CartTypes.CartShippingMethodDTO>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let toDelete: string[]
|
||||
if (isObject(methodIdsOrSelector)) {
|
||||
const methods = await this.listShippingMethods(
|
||||
{
|
||||
...(methodIdsOrSelector as Partial<CartTypes.CartShippingMethodDTO>),
|
||||
},
|
||||
{},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
toDelete = methods.map((m) => m.id)
|
||||
} else {
|
||||
toDelete = Array.isArray(methodIdsOrSelector)
|
||||
? methodIdsOrSelector
|
||||
: [methodIdsOrSelector]
|
||||
}
|
||||
await this.shippingMethodService_.softDelete(toDelete, sharedContext)
|
||||
}
|
||||
|
||||
async addLineItemAdjustments(
|
||||
adjustments: CartTypes.CreateLineItemAdjustmentDTO[]
|
||||
): Promise<CartTypes.LineItemAdjustmentDTO[]>
|
||||
@@ -754,46 +679,6 @@ export default class CartModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
async removeLineItemAdjustments(
|
||||
adjustmentIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeLineItemAdjustments(
|
||||
adjustmentId: string,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeLineItemAdjustments(
|
||||
selector: Partial<CartTypes.LineItemAdjustmentDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
async removeLineItemAdjustments(
|
||||
adjustmentIdsOrSelector:
|
||||
| string
|
||||
| string[]
|
||||
| Partial<CartTypes.LineItemAdjustmentDTO>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let ids: string[]
|
||||
if (isObject(adjustmentIdsOrSelector)) {
|
||||
const adjustments = await this.listLineItemAdjustments(
|
||||
{
|
||||
...adjustmentIdsOrSelector,
|
||||
} as Partial<CartTypes.LineItemAdjustmentDTO>,
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
ids = adjustments.map((adj) => adj.id)
|
||||
} else {
|
||||
ids = Array.isArray(adjustmentIdsOrSelector)
|
||||
? adjustmentIdsOrSelector
|
||||
: [adjustmentIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemAdjustmentService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async setShippingMethodAdjustments(
|
||||
cartId: string,
|
||||
@@ -923,46 +808,6 @@ export default class CartModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
async removeShippingMethodAdjustments(
|
||||
adjustmentIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeShippingMethodAdjustments(
|
||||
adjustmentId: string,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
async removeShippingMethodAdjustments(
|
||||
selector: Partial<CartTypes.ShippingMethodAdjustmentDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
async removeShippingMethodAdjustments(
|
||||
adjustmentIdsOrSelector:
|
||||
| string
|
||||
| string[]
|
||||
| Partial<CartTypes.ShippingMethodAdjustmentDTO>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let ids: string[]
|
||||
if (isObject(adjustmentIdsOrSelector)) {
|
||||
const adjustments = await this.listShippingMethodAdjustments(
|
||||
{
|
||||
...adjustmentIdsOrSelector,
|
||||
} as Partial<CartTypes.ShippingMethodAdjustmentDTO>,
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
ids = adjustments.map((adj) => adj.id)
|
||||
} else {
|
||||
ids = Array.isArray(adjustmentIdsOrSelector)
|
||||
? adjustmentIdsOrSelector
|
||||
: [adjustmentIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.shippingMethodAdjustmentService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
addLineItemTaxLines(
|
||||
taxLines: CartTypes.CreateLineItemTaxLineDTO[]
|
||||
): Promise<CartTypes.LineItemTaxLineDTO[]>
|
||||
@@ -1077,46 +922,6 @@ export default class CartModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
removeLineItemTaxLines(
|
||||
taxLineIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
removeLineItemTaxLines(
|
||||
taxLineIds: string,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
removeLineItemTaxLines(
|
||||
selector: FilterableLineItemTaxLineProps,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
async removeLineItemTaxLines(
|
||||
taxLineIdsOrSelector:
|
||||
| string
|
||||
| string[]
|
||||
| CartTypes.FilterableShippingMethodTaxLineProps,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let ids: string[]
|
||||
if (isObject(taxLineIdsOrSelector)) {
|
||||
const taxLines = await this.listLineItemTaxLines(
|
||||
{
|
||||
...(taxLineIdsOrSelector as CartTypes.FilterableLineItemTaxLineProps),
|
||||
},
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
ids = taxLines.map((taxLine) => taxLine.id)
|
||||
} else {
|
||||
ids = Array.isArray(taxLineIdsOrSelector)
|
||||
? taxLineIdsOrSelector
|
||||
: [taxLineIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.lineItemTaxLineService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
|
||||
addShippingMethodTaxLines(
|
||||
taxLines: CartTypes.CreateShippingMethodTaxLineDTO[]
|
||||
): Promise<CartTypes.ShippingMethodTaxLineDTO[]>
|
||||
@@ -1233,44 +1038,4 @@ export default class CartModuleService<
|
||||
populate: true,
|
||||
})
|
||||
}
|
||||
|
||||
removeShippingMethodTaxLines(
|
||||
taxLineIds: string[],
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
removeShippingMethodTaxLines(
|
||||
taxLineIds: string,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
removeShippingMethodTaxLines(
|
||||
selector: Partial<CartTypes.ShippingMethodTaxLineDTO>,
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
async removeShippingMethodTaxLines(
|
||||
taxLineIdsOrSelector:
|
||||
| string
|
||||
| string[]
|
||||
| CartTypes.FilterableShippingMethodTaxLineProps,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<void> {
|
||||
let ids: string[]
|
||||
if (isObject(taxLineIdsOrSelector)) {
|
||||
const taxLines = await this.listShippingMethodTaxLines(
|
||||
{
|
||||
...(taxLineIdsOrSelector as CartTypes.FilterableShippingMethodTaxLineProps),
|
||||
},
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
ids = taxLines.map((taxLine) => taxLine.id)
|
||||
} else {
|
||||
ids = Array.isArray(taxLineIdsOrSelector)
|
||||
? taxLineIdsOrSelector
|
||||
: [taxLineIdsOrSelector]
|
||||
}
|
||||
|
||||
await this.shippingMethodTaxLineService_.softDelete(ids, sharedContext)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user