chore(): Improve cart module (#13472)
* chore(): Improve cart module * Create giant-spoons-crash.md
This commit is contained in:
1 parent
a4b72f9a21
commit
8dd9ae3d35
2 files changed
+35
-8
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/cart": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(): Improve cart module
|
||||||
@@ -460,7 +460,7 @@ export default class CartModuleService
|
|||||||
items: CartTypes.CreateLineItemDTO[],
|
items: CartTypes.CreateLineItemDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<InferEntityType<typeof LineItem>[]> {
|
): Promise<InferEntityType<typeof LineItem>[]> {
|
||||||
const cart = await this.retrieveCart(
|
const cart = await this.cartService_.retrieve(
|
||||||
cartId,
|
cartId,
|
||||||
{ select: ["id"] },
|
{ select: ["id"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -731,7 +731,7 @@ export default class CartModuleService
|
|||||||
data: CartTypes.CreateShippingMethodForSingleCartDTO[],
|
data: CartTypes.CreateShippingMethodForSingleCartDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<InferEntityType<typeof ShippingMethod>[]> {
|
): Promise<InferEntityType<typeof ShippingMethod>[]> {
|
||||||
const cart = await this.retrieveCart(
|
const cart = await this.cartService_.retrieve(
|
||||||
cartId,
|
cartId,
|
||||||
{ select: ["id"] },
|
{ select: ["id"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -802,7 +802,7 @@ export default class CartModuleService
|
|||||||
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
|
): 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.cartService_.retrieve(
|
||||||
cartIdOrData,
|
cartIdOrData,
|
||||||
{ select: ["id"], relations: ["items"] },
|
{ select: ["id"], relations: ["items"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -1005,7 +1005,7 @@ export default class CartModuleService
|
|||||||
)[],
|
)[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
|
): Promise<InferEntityType<typeof LineItemAdjustment>[]> {
|
||||||
const cart = await this.retrieveCart(
|
const cart = await this.cartService_.retrieve(
|
||||||
cartId,
|
cartId,
|
||||||
{ select: ["id"], relations: ["items.adjustments"] },
|
{ select: ["id"], relations: ["items.adjustments"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -1079,7 +1079,7 @@ export default class CartModuleService
|
|||||||
)[],
|
)[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> {
|
): Promise<InferEntityType<typeof ShippingMethodAdjustment>[]> {
|
||||||
const cart = await this.retrieveCart(
|
const cart = await this.cartService_.retrieve(
|
||||||
cartId,
|
cartId,
|
||||||
{ select: ["id"], relations: ["shipping_methods.adjustments"] },
|
{ select: ["id"], relations: ["shipping_methods.adjustments"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -1176,7 +1176,7 @@ export default class CartModuleService
|
|||||||
let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] =
|
let addedAdjustments: InferEntityType<typeof ShippingMethodAdjustment>[] =
|
||||||
[]
|
[]
|
||||||
if (isString(cartIdOrData)) {
|
if (isString(cartIdOrData)) {
|
||||||
const cart = await this.retrieveCart(
|
const cart = await this.cartService_.retrieve(
|
||||||
cartIdOrData,
|
cartIdOrData,
|
||||||
{ select: ["id"], relations: ["shipping_methods"] },
|
{ select: ["id"], relations: ["shipping_methods"] },
|
||||||
sharedContext
|
sharedContext
|
||||||
@@ -1267,7 +1267,18 @@ export default class CartModuleService
|
|||||||
let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[]
|
let addedTaxLines: InferEntityType<typeof LineItemTaxLine>[]
|
||||||
if (isString(cartIdOrData)) {
|
if (isString(cartIdOrData)) {
|
||||||
// existence check
|
// existence check
|
||||||
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)
|
const cart = await this.cartService_.retrieve(
|
||||||
|
cartIdOrData,
|
||||||
|
{ select: ["id"] },
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!cart) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.INVALID_DATA,
|
||||||
|
`Cart with id ${cartIdOrData} does not exist`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||||
|
|
||||||
@@ -1416,7 +1427,18 @@ export default class CartModuleService
|
|||||||
let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[]
|
let addedTaxLines: InferEntityType<typeof ShippingMethodTaxLine>[]
|
||||||
if (isString(cartIdOrData)) {
|
if (isString(cartIdOrData)) {
|
||||||
// existence check
|
// existence check
|
||||||
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)
|
const cart = await this.cartService_.retrieve(
|
||||||
|
cartIdOrData,
|
||||||
|
{ select: ["id"] },
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!cart) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.INVALID_DATA,
|
||||||
|
`Cart with id ${cartIdOrData} does not exist`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user