fix: make packages/medusa/src/api/routes/store/carts pass eslint (#652)

This commit is contained in:
Leo Leone
2021-10-29 06:18:38 -03:00
committed by GitHub
parent 2c415ea520
commit 1ba63cce08
16 changed files with 432 additions and 491 deletions

View File

@@ -26,7 +26,6 @@
/packages/medusa/src/api/routes/admin/collections
/packages/medusa/src/api/routes/admin/notes
/packages/medusa/src/api/routes/admin/store
/packages/medusa/src/api/routes/store/carts
/packages/medusa/src/api/routes/store/return-reasons
/packages/medusa/src/api/routes/store/returns
/packages/medusa/src/api/routes/store/swaps

View File

@@ -1,4 +1,3 @@
import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"
@@ -36,31 +35,27 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async (m) => {
const txCartService = cartService.withTransaction(m)
await manager.transaction(async (m) => {
const txCartService = cartService.withTransaction(m)
await txCartService.addShippingMethod(id, value.option_id, value.data)
await txCartService.addShippingMethod(id, value.option_id, value.data)
const updated = await txCartService.retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length) {
await txCartService.setPaymentSessions(id)
}
const updated = await txCartService.retrieve(id, {
relations: ["payment_sessions"],
})
const updatedCart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
if (updated.payment_sessions?.length) {
await txCartService.setPaymentSessions(id)
}
})
res.status(200).json({ cart: updatedCart })
} catch (err) {
throw err
}
const updatedCart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart: updatedCart })
}

View File

@@ -57,226 +57,222 @@ export default async (req, res) => {
res.setHeader("Access-Control-Expose-Headers", "Idempotency-Key")
res.setHeader("Idempotency-Key", idempotencyKey.idempotency_key)
try {
const cartService = req.scope.resolve("cartService")
const orderService = req.scope.resolve("orderService")
const swapService = req.scope.resolve("swapService")
const cartService = req.scope.resolve("cartService")
const orderService = req.scope.resolve("orderService")
const swapService = req.scope.resolve("swapService")
let inProgress = true
let err = false
let inProgress = true
let err = false
while (inProgress) {
switch (idempotencyKey.recovery_point) {
case "started": {
const { key, error } = await idempotencyKeyService.workStage(
idempotencyKey.idempotency_key,
async (manager) => {
let cart = await cartService.withTransaction(manager).retrieve(id)
while (inProgress) {
switch (idempotencyKey.recovery_point) {
case "started": {
const { key, error } = await idempotencyKeyService.workStage(
idempotencyKey.idempotency_key,
async (manager) => {
let cart = await cartService.withTransaction(manager).retrieve(id)
if (cart.completed_at) {
if (cart.completed_at) {
return {
response_code: 409,
response_body: {
code: MedusaError.Codes.CART_INCOMPATIBLE_STATE,
message: "Cart has already been completed",
type: MedusaError.Types.NOT_ALLOWED,
},
}
}
cart = await cartService
.withTransaction(manager)
.authorizePayment(id, {
...req.request_context,
idempotency_key: idempotencyKey.idempotency_key,
})
if (cart.payment_session) {
if (
cart.payment_session.status === "requires_more" ||
cart.payment_session.status === "pending"
) {
return {
response_code: 409,
response_code: 200,
response_body: {
code: MedusaError.Codes.CART_INCOMPATIBLE_STATE,
message: "Cart has already been completed",
type: MedusaError.Types.NOT_ALLOWED,
data: cart,
payment_status: cart.payment_session.status,
type: "cart",
},
}
}
}
cart = await cartService
.withTransaction(manager)
.authorizePayment(id, {
...req.request_context,
idempotency_key: idempotencyKey.idempotency_key,
})
return {
recovery_point: "payment_authorized",
}
}
)
if (error) {
inProgress = false
err = error
} else {
idempotencyKey = key
}
break
}
case "payment_authorized": {
const { key, error } = await idempotencyKeyService.workStage(
idempotencyKey.idempotency_key,
async (manager) => {
const cart = await cartService
.withTransaction(manager)
.retrieve(id, {
select: ["total"],
relations: ["payment", "payment_sessions"],
})
let order
// If cart is part of swap, we register swap as complete
switch (cart.type) {
case "swap": {
try {
const swapId = cart.metadata?.swap_id
let swap = await swapService
.withTransaction(manager)
.registerCartCompletion(swapId)
swap = await swapService
.withTransaction(manager)
.retrieve(swap.id, { relations: ["shipping_address"] })
if (cart.payment_session) {
if (
cart.payment_session.status === "requires_more" ||
cart.payment_session.status === "pending"
) {
return {
response_code: 200,
response_body: {
data: cart,
payment_status: cart.payment_session.status,
type: "cart",
},
response_body: { data: swap, type: "swap" },
}
} catch (error) {
if (
error &&
error.code === MedusaError.Codes.INSUFFICIENT_INVENTORY
) {
return {
response_code: 409,
response_body: {
message: error.message,
type: error.type,
code: error.code,
},
}
} else {
throw error
}
}
}
// case "payment_link":
default: {
if (!cart.payment && cart.total > 0) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Cart payment not authorized`
)
}
return {
recovery_point: "payment_authorized",
}
}
)
if (error) {
inProgress = false
err = error
} else {
idempotencyKey = key
}
break
}
case "payment_authorized": {
const { key, error } = await idempotencyKeyService.workStage(
idempotencyKey.idempotency_key,
async (manager) => {
const cart = await cartService
.withTransaction(manager)
.retrieve(id, {
select: ["total"],
relations: ["payment", "payment_sessions"],
})
let order
// If cart is part of swap, we register swap as complete
switch (cart.type) {
case "swap": {
try {
const swapId = cart.metadata?.swap_id
let swap = await swapService
try {
order = await orderService
.withTransaction(manager)
.createFromCart(cart.id)
} catch (error) {
if (
error &&
error.message === "Order from cart already exists"
) {
order = await orderService
.withTransaction(manager)
.registerCartCompletion(swapId)
swap = await swapService
.withTransaction(manager)
.retrieve(swap.id, { relations: ["shipping_address"] })
.retrieveByCartId(id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: ["shipping_address", "items", "payments"],
})
return {
response_code: 200,
response_body: { data: swap, type: "swap" },
response_body: { data: order, type: "order" },
}
} catch (error) {
if (
error &&
error.code === MedusaError.Codes.INSUFFICIENT_INVENTORY
) {
return {
response_code: 409,
response_body: {
message: error.message,
type: error.type,
code: error.code,
},
}
} else {
throw error
} else if (
error &&
error.code === MedusaError.Codes.INSUFFICIENT_INVENTORY
) {
return {
response_code: 409,
response_body: {
message: error.message,
type: error.type,
code: error.code,
},
}
} else {
throw error
}
}
// case "payment_link":
default: {
if (!cart.payment && cart.total > 0) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Cart payment not authorized`
)
}
try {
order = await orderService
.withTransaction(manager)
.createFromCart(cart.id)
} catch (error) {
if (
error &&
error.message === "Order from cart already exists"
) {
order = await orderService
.withTransaction(manager)
.retrieveByCartId(id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: ["shipping_address", "items", "payments"],
})
return {
response_code: 200,
response_body: { data: order, type: "order" },
}
} else if (
error &&
error.code === MedusaError.Codes.INSUFFICIENT_INVENTORY
) {
return {
response_code: 409,
response_body: {
message: error.message,
type: error.type,
code: error.code,
},
}
} else {
throw error
}
}
}
}
order = await orderService
.withTransaction(manager)
.retrieve(order.id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: ["shipping_address", "items", "payments"],
})
return {
response_code: 200,
response_body: { data: order, type: "order" },
}
}
)
if (error) {
inProgress = false
err = error
} else {
idempotencyKey = key
order = await orderService
.withTransaction(manager)
.retrieve(order.id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: ["shipping_address", "items", "payments"],
})
return {
response_code: 200,
response_body: { data: order, type: "order" },
}
}
break
}
)
case "finished": {
if (error) {
inProgress = false
break
err = error
} else {
idempotencyKey = key
}
default:
idempotencyKey = await idempotencyKeyService.update(
idempotencyKey.idempotency_key,
{
recovery_point: "finished",
response_code: 500,
response_body: { message: "Unknown recovery point" },
}
)
break
break
}
}
if (err) {
throw err
}
case "finished": {
inProgress = false
break
}
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
} catch (error) {
throw error
default:
idempotencyKey = await idempotencyKeyService.update(
idempotencyKey.idempotency_key,
{
recovery_point: "finished",
response_code: 500,
response_body: { message: "Unknown recovery point" },
}
)
break
}
}
if (err) {
throw err
}
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
}

View File

@@ -70,74 +70,70 @@ export default async (req, res) => {
user_agent: req.get("user-agent"),
}
try {
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
const entityManager = req.scope.resolve("manager")
const entityManager = req.scope.resolve("manager")
await entityManager.transaction(async (manager) => {
// Add a default region if no region has been specified
let regionId = value.region_id
if (!value.region_id) {
const regionService = req.scope.resolve("regionService")
const regions = await regionService.withTransaction(manager).list({})
await entityManager.transaction(async (manager) => {
// Add a default region if no region has been specified
let regionId = value.region_id
if (!value.region_id) {
const regionService = req.scope.resolve("regionService")
const regions = await regionService.withTransaction(manager).list({})
if (!regions?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`A region is required to create a cart`
)
}
regionId = regions[0].id
}
const toCreate = {
region_id: regionId,
context: {
...reqContext,
...value.context,
},
}
if (req.user && req.user.customer_id) {
const customerService = req.scope.resolve("customerService")
const customer = await customerService
.withTransaction(manager)
.retrieve(req.user.customer_id)
toCreate.customer_id = customer.id
toCreate.email = customer.email
}
if (value.country_code) {
toCreate.shipping_address = {
country_code: value.country_code.toLowerCase(),
}
}
let cart = await cartService.withTransaction(manager).create(toCreate)
if (value.items) {
await Promise.all(
value.items.map(async (i) => {
await lineItemService.withTransaction(manager).create({
cart_id: cart.id,
variant_id: i.variant_id,
quantity: i.quantity,
region_id: value.region_id,
})
})
if (!regions?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`A region is required to create a cart`
)
}
cart = await cartService.withTransaction(manager).retrieve(cart.id, {
select: defaultFields,
relations: defaultRelations,
})
regionId = regions[0].id
}
res.status(200).json({ cart })
const toCreate = {
region_id: regionId,
context: {
...reqContext,
...value.context,
},
}
if (req.user && req.user.customer_id) {
const customerService = req.scope.resolve("customerService")
const customer = await customerService
.withTransaction(manager)
.retrieve(req.user.customer_id)
toCreate.customer_id = customer.id
toCreate.email = customer.email
}
if (value.country_code) {
toCreate.shipping_address = {
country_code: value.country_code.toLowerCase(),
}
}
let cart = await cartService.withTransaction(manager).create(toCreate)
if (value.items) {
await Promise.all(
value.items.map(async (i) => {
await lineItemService.withTransaction(manager).create({
cart_id: cart.id,
variant_id: i.variant_id,
quantity: i.quantity,
region_id: value.region_id,
})
})
)
}
cart = await cartService.withTransaction(manager).retrieve(cart.id, {
select: defaultFields,
relations: defaultRelations,
})
} catch (err) {
throw err
}
res.status(200).json({ cart })
})
}

View File

@@ -38,38 +38,34 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const manager = req.scope.resolve("manager")
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
const manager = req.scope.resolve("manager")
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async (m) => {
const txCartService = cartService.withTransaction(m)
const cart = await txCartService.retrieve(id)
await manager.transaction(async (m) => {
const txCartService = cartService.withTransaction(m)
const cart = await txCartService.retrieve(id)
const line = await lineItemService
.withTransaction(m)
.generate(value.variant_id, cart.region_id, value.quantity, {
metadata: value.metadata,
})
await txCartService.addLineItem(id, line)
const updated = await txCartService.retrieve(id, {
relations: ["payment_sessions"],
const line = await lineItemService
.withTransaction(m)
.generate(value.variant_id, cart.region_id, value.quantity, {
metadata: value.metadata,
})
await txCartService.addLineItem(id, line)
if (updated.payment_sessions?.length) {
await txCartService.setPaymentSessions(id)
}
const updated = await txCartService.retrieve(id, {
relations: ["payment_sessions"],
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
if (updated.payment_sessions?.length) {
await txCartService.setPaymentSessions(id)
}
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
}

View File

@@ -22,18 +22,14 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id } = req.params
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
await cartService.setPaymentSessions(id)
await cartService.setPaymentSessions(id)
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}

View File

@@ -23,31 +23,27 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, code } = req.params
try {
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async (m) => {
// Remove the discount
await cartService.withTransaction(m).removeDiscount(id, code)
await manager.transaction(async (m) => {
// Remove the discount
await cartService.withTransaction(m).removeDiscount(id, code)
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
}

View File

@@ -23,31 +23,27 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, line_id } = req.params
try {
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async (m) => {
// Remove the line item
await cartService.withTransaction(m).removeLineItem(id, line_id)
await manager.transaction(async (m) => {
// Remove the line item
await cartService.withTransaction(m).removeLineItem(id, line_id)
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
}

View File

@@ -23,17 +23,13 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, provider_id } = req.params
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
await cartService.deletePaymentSession(id, provider_id)
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
await cartService.deletePaymentSession(id, provider_id)
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}

View File

@@ -22,33 +22,29 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id } = req.params
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
let cart = await cartService.retrieve(id, {
relations: ["customer"],
})
let cart = await cartService.retrieve(id, {
relations: ["customer"],
})
// If there is a logged in user add the user to the cart
if (req.user && req.user.customer_id) {
if (
!cart.customer_id ||
!cart.email ||
cart.customer_id !== req.user.customer_id
) {
await cartService.update(id, {
customer_id: req.user.customer_id,
})
}
// If there is a logged in user add the user to the cart
if (req.user && req.user.customer_id) {
if (
!cart.customer_id ||
!cart.email ||
cart.customer_id !== req.user.customer_id
) {
await cartService.update(id, {
customer_id: req.user.customer_id,
})
}
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.json({ cart })
} catch (err) {
throw err
}
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.json({ cart })
}

View File

@@ -21,30 +21,26 @@
export default async (req, res) => {
const { id, provider_id } = req.params
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
await cartService.refreshPaymentSession(id, provider_id)
const cart = await cartService.retrieve(id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: [
"region",
"region.countries",
"region.payment_providers",
"shipping_methods",
"payment_sessions",
"shipping_methods.shipping_option",
],
})
await cartService.refreshPaymentSession(id, provider_id)
const cart = await cartService.retrieve(id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: [
"region",
"region.countries",
"region.payment_providers",
"shipping_methods",
"payment_sessions",
"shipping_methods.shipping_option",
],
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}

View File

@@ -33,17 +33,13 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
let cart = await cartService.setPaymentSession(id, value.provider_id)
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
let cart = await cartService.setPaymentSession(id, value.provider_id)
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}

View File

@@ -1,4 +1,3 @@
import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils"
import { defaultFields, defaultRelations } from "./"

View File

@@ -34,53 +34,49 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
await manager.transaction(async (m) => {
// If the quantity is 0 that is effectively deletion
if (value.quantity === 0) {
await cartService.withTransaction(m).removeLineItem(id, line_id)
} else {
const cart = await cartService.retrieve(id, { relations: ["items"] })
await manager.transaction(async (m) => {
// If the quantity is 0 that is effectively deletion
if (value.quantity === 0) {
await cartService.withTransaction(m).removeLineItem(id, line_id)
} else {
const cart = await cartService.retrieve(id, { relations: ["items"] })
const existing = cart.items.find((i) => i.id === line_id)
if (!existing) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Could not find the line item"
)
}
const lineItemUpdate = {
variant_id: existing.variant.id,
region_id: cart.region_id,
quantity: value.quantity,
metadata: existing.metadata || {},
}
await cartService
.withTransaction(m)
.updateLineItem(id, line_id, lineItemUpdate)
const existing = cart.items.find((i) => i.id === line_id)
if (!existing) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Could not find the line item"
)
}
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
const lineItemUpdate = {
variant_id: existing.variant.id,
region_id: cart.region_id,
quantity: value.quantity,
metadata: existing.metadata || {},
}
await cartService
.withTransaction(m)
.updateLineItem(id, line_id, lineItemUpdate)
}
// If the cart has payment sessions update these
const updated = await cartService.withTransaction(m).retrieve(id, {
relations: ["payment_sessions"],
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
if (updated.payment_sessions?.length) {
await cartService.withTransaction(m).setPaymentSessions(id)
}
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
}

View File

@@ -14,17 +14,13 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
let cart = await cartService.setPaymentMethod(id, value)
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
let cart = await cartService.setPaymentMethod(id, value)
cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}

View File

@@ -35,19 +35,15 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
try {
const cartService = req.scope.resolve("cartService")
const cartService = req.scope.resolve("cartService")
await cartService.setPaymentSession(id, provider_id)
await cartService.updatePaymentSession(id, value.data)
await cartService.setPaymentSession(id, provider_id)
await cartService.updatePaymentSession(id, value.data)
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
res.status(200).json({ cart })
}