chore(): Cart fixes and opti (#13455)

**What**
- Remove overserialization
- fix wrong transaction usage
- call the right service instead of higher level methods
This commit is contained in:
Adrien de Peretti
2025-09-10 12:53:36 +02:00
committed by GitHub
parent ac09b3cbef
commit 49a4caa62d
2 changed files with 295 additions and 72 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/cart": patch
---
chore(): Cart fixes and opti

View File

@@ -36,9 +36,7 @@ import {
} from "@models" } from "@models"
import { import {
CreateLineItemDTO, CreateLineItemDTO,
CreateLineItemTaxLineDTO,
CreateShippingMethodDTO, CreateShippingMethodDTO,
CreateShippingMethodTaxLineDTO,
UpdateLineItemDTO, UpdateLineItemDTO,
UpdateShippingMethodTaxLineDTO, UpdateShippingMethodTaxLineDTO,
} from "@types" } from "@types"
@@ -579,7 +577,11 @@ export default class CartModuleService
): Promise<InferEntityType<typeof LineItem>[]> { ): Promise<InferEntityType<typeof LineItem>[]> {
let toUpdate: UpdateLineItemDTO[] = [] let toUpdate: UpdateLineItemDTO[] = []
for (const { selector, data } of updates) { for (const { selector, data } of updates) {
const items = await this.listLineItems({ ...selector }, {}, sharedContext) const items = await this.lineItemService_.list(
{ ...selector },
{},
sharedContext
)
items.forEach((item) => { items.forEach((item) => {
toUpdate.push({ toUpdate.push({
@@ -760,7 +762,7 @@ export default class CartModuleService
sharedContext?: Context sharedContext?: Context
): Promise<CartTypes.LineItemAdjustmentDTO[]> ): Promise<CartTypes.LineItemAdjustmentDTO[]>
@InjectTransactionManager() @InjectManager()
async addLineItemAdjustments( async addLineItemAdjustments(
cartIdOrData: cartIdOrData:
| string | string
@@ -769,6 +771,26 @@ export default class CartModuleService
adjustments?: CartTypes.CreateLineItemAdjustmentDTO[], adjustments?: CartTypes.CreateLineItemAdjustmentDTO[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemAdjustmentDTO[]> { ): Promise<CartTypes.LineItemAdjustmentDTO[]> {
const result = await this.addLineItemAdjustments_(
cartIdOrData,
adjustments,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.LineItemAdjustmentDTO[]
>(result)
}
@InjectTransactionManager()
protected async addLineItemAdjustments_(
cartIdOrData:
| string
| CartTypes.CreateLineItemAdjustmentDTO[]
| CartTypes.CreateLineItemAdjustmentDTO,
adjustments?: CartTypes.CreateLineItemAdjustmentDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
let addedAdjustments: InferEntityType<typeof LineItemAdjustment>[] = [] let addedAdjustments: InferEntityType<typeof LineItemAdjustment>[] = []
if (isString(cartIdOrData)) { if (isString(cartIdOrData)) {
const cart = await this.retrieveCart( const cart = await this.retrieveCart(
@@ -801,12 +823,10 @@ export default class CartModuleService
) )
} }
return await this.baseRepository_.serialize< return addedAdjustments
CartTypes.LineItemAdjustmentDTO[]
>(addedAdjustments)
} }
@InjectTransactionManager() @InjectManager()
async upsertLineItemTaxLines( async upsertLineItemTaxLines(
taxLines: ( taxLines: (
| CartTypes.CreateLineItemTaxLineDTO | CartTypes.CreateLineItemTaxLineDTO
@@ -825,6 +845,22 @@ export default class CartModuleService
} }
@InjectTransactionManager() @InjectTransactionManager()
protected async upsertLineItemTaxLines_(
taxLines: (
| CartTypes.CreateLineItemTaxLineDTO
| CartTypes.UpdateLineItemTaxLineDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof LineItemTaxLine>[]> {
const result = await this.lineItemTaxLineService_.upsert(
taxLines as CartTypes.UpdateLineItemTaxLineDTO[],
sharedContext
)
return result
}
@InjectManager()
async upsertLineItemAdjustments( async upsertLineItemAdjustments(
adjustments: ( adjustments: (
| CartTypes.CreateLineItemAdjustmentDTO | CartTypes.CreateLineItemAdjustmentDTO
@@ -832,7 +868,7 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemAdjustmentDTO[]> { ): Promise<CartTypes.LineItemAdjustmentDTO[]> {
let result = await this.lineItemAdjustmentService_.upsert( const result = await this.upsertLineItemAdjustments_(
adjustments, adjustments,
sharedContext sharedContext
) )
@@ -843,6 +879,22 @@ export default class CartModuleService
} }
@InjectTransactionManager() @InjectTransactionManager()
protected async upsertLineItemAdjustments_(
adjustments: (
| CartTypes.CreateLineItemAdjustmentDTO
| CartTypes.UpdateLineItemAdjustmentDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
let result = await this.lineItemAdjustmentService_.upsert(
adjustments,
sharedContext
)
return result
}
@InjectManager()
async upsertShippingMethodTaxLines( async upsertShippingMethodTaxLines(
taxLines: ( taxLines: (
| CartTypes.CreateShippingMethodTaxLineDTO | CartTypes.CreateShippingMethodTaxLineDTO
@@ -850,8 +902,8 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> { ): Promise<CartTypes.ShippingMethodTaxLineDTO[]> {
const result = await this.shippingMethodTaxLineService_.upsert( const result = await this.upsertShippingMethodTaxLines_(
taxLines as UpdateShippingMethodTaxLineDTO[], taxLines,
sharedContext sharedContext
) )
@@ -861,6 +913,22 @@ export default class CartModuleService
} }
@InjectTransactionManager() @InjectTransactionManager()
protected async upsertShippingMethodTaxLines_(
taxLines: (
| CartTypes.CreateShippingMethodTaxLineDTO
| CartTypes.UpdateShippingMethodTaxLineDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof ShippingMethodTaxLine>[]> {
const result = await this.shippingMethodTaxLineService_.upsert(
taxLines as UpdateShippingMethodTaxLineDTO[],
sharedContext
)
return result
}
@InjectManager()
async upsertShippingMethodAdjustments( async upsertShippingMethodAdjustments(
adjustments: ( adjustments: (
| CartTypes.CreateShippingMethodAdjustmentDTO | CartTypes.CreateShippingMethodAdjustmentDTO
@@ -868,7 +936,7 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> { ): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> {
const result = await this.shippingMethodAdjustmentService_.upsert( const result = await this.upsertShippingMethodAdjustments_(
adjustments, adjustments,
sharedContext sharedContext
) )
@@ -879,6 +947,22 @@ export default class CartModuleService
} }
@InjectTransactionManager() @InjectTransactionManager()
protected async upsertShippingMethodAdjustments_(
adjustments: (
| CartTypes.CreateShippingMethodAdjustmentDTO
| CartTypes.UpdateShippingMethodAdjustmentDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> {
const result = await this.shippingMethodAdjustmentService_.upsert(
adjustments,
sharedContext
)
return result
}
@InjectManager()
async setLineItemAdjustments( async setLineItemAdjustments(
cartId: string, cartId: string,
adjustments: ( adjustments: (
@@ -887,13 +971,33 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemAdjustmentDTO[]> { ): Promise<CartTypes.LineItemAdjustmentDTO[]> {
const result = await this.setLineItemAdjustments_(
cartId,
adjustments,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.LineItemAdjustmentDTO[]
>(result)
}
@InjectTransactionManager()
protected async setLineItemAdjustments_(
cartId: string,
adjustments: (
| CartTypes.CreateLineItemAdjustmentDTO
| CartTypes.UpdateLineItemAdjustmentDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
const cart = await this.retrieveCart( const cart = await this.retrieveCart(
cartId, cartId,
{ select: ["id"], relations: ["items.adjustments"] }, { select: ["id"], relations: ["items.adjustments"] },
sharedContext sharedContext
) )
const existingAdjustments = await this.listLineItemAdjustments( const existingAdjustments = await this.lineItemAdjustmentService_.list(
{ item: { cart_id: cart.id } }, { item: { cart_id: cart.id } },
{ select: ["id"] }, { select: ["id"] },
sharedContext sharedContext
@@ -905,14 +1009,16 @@ export default class CartModuleService
.filter(Boolean) .filter(Boolean)
) )
const toDelete: CartTypes.LineItemAdjustmentDTO[] = [] const toDelete: InferEntityType<typeof LineItemAdjustment>[] = []
// From the existing adjustments, find the ones that are not passed in adjustments // From the existing adjustments, find the ones that are not passed in adjustments
existingAdjustments.forEach((adj: CartTypes.LineItemAdjustmentDTO) => { existingAdjustments.forEach(
if (!adjustmentsSet.has(adj.id)) { (adj: InferEntityType<typeof LineItemAdjustment>) => {
toDelete.push(adj) if (!adjustmentsSet.has(adj.id)) {
toDelete.push(adj)
}
} }
}) )
if (toDelete.length) { if (toDelete.length) {
await this.lineItemAdjustmentService_.softDelete( await this.lineItemAdjustmentService_.softDelete(
@@ -926,12 +1032,10 @@ export default class CartModuleService
sharedContext sharedContext
) )
return await this.baseRepository_.serialize< return result
CartTypes.LineItemAdjustmentDTO[]
>(result)
} }
@InjectTransactionManager() @InjectManager()
async setShippingMethodAdjustments( async setShippingMethodAdjustments(
cartId: string, cartId: string,
adjustments: ( adjustments: (
@@ -940,17 +1044,38 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> { ): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> {
const result = await this.setShippingMethodAdjustments_(
cartId,
adjustments,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.ShippingMethodAdjustmentDTO[]
>(result)
}
@InjectTransactionManager()
protected async setShippingMethodAdjustments_(
cartId: string,
adjustments: (
| CartTypes.CreateShippingMethodAdjustmentDTO
| CartTypes.UpdateShippingMethodAdjustmentDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> {
const cart = await this.retrieveCart( const cart = await this.retrieveCart(
cartId, cartId,
{ select: ["id"], relations: ["shipping_methods.adjustments"] }, { select: ["id"], relations: ["shipping_methods.adjustments"] },
sharedContext sharedContext
) )
const existingAdjustments = await this.listShippingMethodAdjustments( const existingAdjustments =
{ shipping_method: { cart_id: cart.id } }, await this.shippingMethodAdjustmentService_.list(
{ select: ["id"] }, { shipping_method: { cart_id: cart.id } },
sharedContext { select: ["id"] },
) sharedContext
)
const adjustmentsSet = new Set( const adjustmentsSet = new Set(
adjustments adjustments
@@ -958,11 +1083,11 @@ export default class CartModuleService
.filter(Boolean) .filter(Boolean)
) )
const toDelete: CartTypes.ShippingMethodAdjustmentDTO[] = [] const toDelete: InferEntityType<typeof ShippingMethodAdjustment>[] = []
// From the existing adjustments, find the ones that are not passed in adjustments // From the existing adjustments, find the ones that are not passed in adjustments
existingAdjustments.forEach( existingAdjustments.forEach(
(adj: CartTypes.ShippingMethodAdjustmentDTO) => { (adj: InferEntityType<typeof ShippingMethodAdjustment>) => {
if (!adjustmentsSet.has(adj.id)) { if (!adjustmentsSet.has(adj.id)) {
toDelete.push(adj) toDelete.push(adj)
} }
@@ -981,9 +1106,7 @@ export default class CartModuleService
sharedContext sharedContext
) )
return await this.baseRepository_.serialize< return result
CartTypes.ShippingMethodAdjustmentDTO[]
>(result)
} }
async addShippingMethodAdjustments( async addShippingMethodAdjustments(
@@ -998,7 +1121,7 @@ export default class CartModuleService
sharedContext?: Context sharedContext?: Context
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> ): Promise<CartTypes.ShippingMethodAdjustmentDTO[]>
@InjectTransactionManager() @InjectManager()
async addShippingMethodAdjustments( async addShippingMethodAdjustments(
cartIdOrData: cartIdOrData:
| string | string
@@ -1009,6 +1132,30 @@ export default class CartModuleService
): Promise< ): Promise<
| CartTypes.ShippingMethodAdjustmentDTO[] | CartTypes.ShippingMethodAdjustmentDTO[]
| CartTypes.ShippingMethodAdjustmentDTO | CartTypes.ShippingMethodAdjustmentDTO
> {
const result = await this.addShippingMethodAdjustments_(
cartIdOrData,
adjustments,
sharedContext
)
return await this.baseRepository_.serialize<
| CartTypes.ShippingMethodAdjustmentDTO[]
| CartTypes.ShippingMethodAdjustmentDTO
>(result)
}
@InjectTransactionManager()
protected async addShippingMethodAdjustments_(
cartIdOrData:
| string
| CartTypes.CreateShippingMethodAdjustmentDTO[]
| CartTypes.CreateShippingMethodAdjustmentDTO,
adjustments?: CartTypes.CreateShippingMethodAdjustmentDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<
| InferEntityType<typeof ShippingMethodAdjustment>[]
| InferEntityType<typeof ShippingMethodAdjustment>
> { > {
let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] = let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] =
[] []
@@ -1044,18 +1191,13 @@ export default class CartModuleService
} }
if (isObject(cartIdOrData)) { if (isObject(cartIdOrData)) {
return await this.baseRepository_.serialize<CartTypes.ShippingMethodAdjustmentDTO>( return addedAdjustments[0]
addedAdjustments[0],
{}
)
} }
return await this.baseRepository_.serialize< return addedAdjustments
CartTypes.ShippingMethodAdjustmentDTO[]
>(addedAdjustments)
} }
addLineItemTaxLines( async addLineItemTaxLines(
taxLines: CartTypes.CreateLineItemTaxLineDTO[] taxLines: CartTypes.CreateLineItemTaxLineDTO[]
): Promise<CartTypes.LineItemTaxLineDTO[]> ): Promise<CartTypes.LineItemTaxLineDTO[]>
addLineItemTaxLines( addLineItemTaxLines(
@@ -1069,7 +1211,7 @@ export default class CartModuleService
sharedContext?: Context sharedContext?: Context
): Promise<CartTypes.LineItemTaxLineDTO[]> ): Promise<CartTypes.LineItemTaxLineDTO[]>
@InjectTransactionManager() @InjectManager()
async addLineItemTaxLines( async addLineItemTaxLines(
cartIdOrData: cartIdOrData:
| string | string
@@ -1080,6 +1222,31 @@ export default class CartModuleService
| CartTypes.CreateLineItemTaxLineDTO, | CartTypes.CreateLineItemTaxLineDTO,
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO> { ): Promise<CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO> {
const result = await this.addLineItemTaxLines_(
cartIdOrData,
taxLines,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.LineItemTaxLineDTO[] | CartTypes.LineItemTaxLineDTO
>(result)
}
@InjectTransactionManager()
protected async addLineItemTaxLines_(
cartIdOrData:
| string
| CartTypes.CreateLineItemTaxLineDTO[]
| CartTypes.CreateLineItemTaxLineDTO,
taxLines?:
| CartTypes.CreateLineItemTaxLineDTO[]
| CartTypes.CreateLineItemTaxLineDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<
| InferEntityType<typeof LineItemTaxLine>[]
| InferEntityType<typeof LineItemTaxLine>
> {
let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[] let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[]
if (isString(cartIdOrData)) { if (isString(cartIdOrData)) {
// existence check // existence check
@@ -1088,30 +1255,26 @@ export default class CartModuleService
const lines = Array.isArray(taxLines) ? taxLines : [taxLines] const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
addedTaxLines = await this.lineItemTaxLineService_.create( addedTaxLines = await this.lineItemTaxLineService_.create(
lines as CreateLineItemTaxLineDTO[], lines,
sharedContext sharedContext
) )
} else { } else {
const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData] const data = Array.isArray(cartIdOrData) ? cartIdOrData : [cartIdOrData]
addedTaxLines = await this.lineItemTaxLineService_.create( addedTaxLines = await this.lineItemTaxLineService_.create(
data as CreateLineItemTaxLineDTO[], data,
sharedContext sharedContext
) )
} }
const serialized = await this.baseRepository_.serialize<
CartTypes.LineItemTaxLineDTO[]
>(addedTaxLines)
if (isObject(cartIdOrData)) { if (isObject(cartIdOrData)) {
return serialized[0] return addedTaxLines[0]
} }
return serialized return addedTaxLines
} }
@InjectTransactionManager() @InjectManager()
async setLineItemTaxLines( async setLineItemTaxLines(
cartId: string, cartId: string,
taxLines: ( taxLines: (
@@ -1120,6 +1283,26 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.LineItemTaxLineDTO[]> { ): Promise<CartTypes.LineItemTaxLineDTO[]> {
const result = await this.setLineItemTaxLines_(
cartId,
taxLines,
sharedContext
)
return await this.baseRepository_.serialize<CartTypes.LineItemTaxLineDTO[]>(
result
)
}
@InjectTransactionManager()
protected async setLineItemTaxLines_(
cartId: string,
taxLines: (
| CartTypes.CreateLineItemTaxLineDTO
| CartTypes.UpdateLineItemTaxLineDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof LineItemTaxLine>[]> {
const normalizedTaxLines = ( const normalizedTaxLines = (
taxLines as CartTypes.UpdateLineItemTaxLineDTO[] taxLines as CartTypes.UpdateLineItemTaxLineDTO[]
).map((taxLine) => { ).map((taxLine) => {
@@ -1156,9 +1339,7 @@ export default class CartModuleService
this.lineItemTaxLineService_.softDelete(deleteConstraints, sharedContext), this.lineItemTaxLineService_.softDelete(deleteConstraints, sharedContext),
]) ])
return await this.baseRepository_.serialize<CartTypes.LineItemTaxLineDTO[]>( return result
result
)
} }
addShippingMethodTaxLines( addShippingMethodTaxLines(
@@ -1175,7 +1356,7 @@ export default class CartModuleService
sharedContext?: Context sharedContext?: Context
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> ): Promise<CartTypes.ShippingMethodTaxLineDTO[]>
@InjectTransactionManager() @InjectManager()
async addShippingMethodTaxLines( async addShippingMethodTaxLines(
cartIdOrData: cartIdOrData:
| string | string
@@ -1187,6 +1368,31 @@ export default class CartModuleService
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise< ): Promise<
CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO
> {
const result = await this.addShippingMethodTaxLines_(
cartIdOrData,
taxLines,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.ShippingMethodTaxLineDTO[] | CartTypes.ShippingMethodTaxLineDTO
>(result)
}
@InjectTransactionManager()
protected async addShippingMethodTaxLines_(
cartIdOrData:
| string
| CartTypes.CreateShippingMethodTaxLineDTO[]
| CartTypes.CreateShippingMethodTaxLineDTO,
taxLines?:
| CartTypes.CreateShippingMethodTaxLineDTO[]
| CartTypes.CreateShippingMethodTaxLineDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<
| InferEntityType<typeof ShippingMethodTaxLine>[]
| InferEntityType<typeof ShippingMethodTaxLine>
> { > {
let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[] let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[]
if (isString(cartIdOrData)) { if (isString(cartIdOrData)) {
@@ -1196,29 +1402,26 @@ export default class CartModuleService
const lines = Array.isArray(taxLines) ? taxLines : [taxLines] const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
addedTaxLines = await this.shippingMethodTaxLineService_.create( addedTaxLines = await this.shippingMethodTaxLineService_.create(
lines as CreateShippingMethodTaxLineDTO[], lines,
sharedContext sharedContext
) )
} else { } else {
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
addedTaxLines = await this.shippingMethodTaxLineService_.create( addedTaxLines = await this.shippingMethodTaxLineService_.create(
taxLines as CreateShippingMethodTaxLineDTO[], lines,
sharedContext sharedContext
) )
} }
const serialized =
await this.baseRepository_.serialize<CartTypes.ShippingMethodTaxLineDTO>(
addedTaxLines[0]
)
if (isObject(cartIdOrData)) { if (isObject(cartIdOrData)) {
return serialized[0] return addedTaxLines[0]
} }
return serialized return addedTaxLines
} }
@InjectTransactionManager() @InjectManager()
async setShippingMethodTaxLines( async setShippingMethodTaxLines(
cartId: string, cartId: string,
taxLines: ( taxLines: (
@@ -1227,6 +1430,26 @@ export default class CartModuleService
)[], )[],
@MedusaContext() sharedContext: Context = {} @MedusaContext() sharedContext: Context = {}
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> { ): Promise<CartTypes.ShippingMethodTaxLineDTO[]> {
const result = await this.setShippingMethodTaxLines_(
cartId,
taxLines,
sharedContext
)
return await this.baseRepository_.serialize<
CartTypes.ShippingMethodTaxLineDTO[]
>(result)
}
@InjectTransactionManager()
protected async setShippingMethodTaxLines_(
cartId: string,
taxLines: (
| CartTypes.CreateShippingMethodTaxLineDTO
| CartTypes.UpdateShippingMethodTaxLineDTO
)[],
@MedusaContext() sharedContext: Context = {}
): Promise<InferEntityType<typeof ShippingMethodTaxLine>[]> {
const normalizedTaxLines = ( const normalizedTaxLines = (
taxLines as CartTypes.UpdateShippingMethodTaxLineDTO[] taxLines as CartTypes.UpdateShippingMethodTaxLineDTO[]
).map((taxLine) => { ).map((taxLine) => {
@@ -1257,10 +1480,7 @@ export default class CartModuleService
const [result] = await promiseAll([ const [result] = await promiseAll([
taxLines.length taxLines.length
? this.shippingMethodTaxLineService_.upsert( ? this.shippingMethodTaxLineService_.upsert(taxLines, sharedContext)
taxLines as UpdateShippingMethodTaxLineDTO[],
sharedContext
)
: [], : [],
this.shippingMethodTaxLineService_.softDelete( this.shippingMethodTaxLineService_.softDelete(
deleteConstraints, deleteConstraints,
@@ -1268,8 +1488,6 @@ export default class CartModuleService
), ),
]) ])
return await this.baseRepository_.serialize< return result
CartTypes.ShippingMethodTaxLineDTO[]
>(result)
} }
} }