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

Integration tests not passing.
This commit is contained in:
Oliver Windall Juhl
2021-10-29 11:27:40 +02:00
committed by GitHub
parent 1ba63cce08
commit 5ce949f3b0
16 changed files with 491 additions and 432 deletions

View File

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

View File

@@ -57,222 +57,226 @@ export default async (req, res) => {
res.setHeader("Access-Control-Expose-Headers", "Idempotency-Key")
res.setHeader("Idempotency-Key", idempotencyKey.idempotency_key)
const cartService = req.scope.resolve("cartService")
const orderService = req.scope.resolve("orderService")
const swapService = req.scope.resolve("swapService")
try {
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) {
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"
) {
if (cart.completed_at) {
return {
response_code: 200,
response_code: 409,
response_body: {
data: cart,
payment_status: cart.payment_session.status,
type: "cart",
code: MedusaError.Codes.CART_INCOMPATIBLE_STATE,
message: "Cart has already been completed",
type: MedusaError.Types.NOT_ALLOWED,
},
}
}
}
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"] })
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: 200,
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
response_body: {
data: cart,
payment_status: cart.payment_session.status,
type: "cart",
},
}
}
}
// 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
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)
.retrieveByCartId(id, {
select: [
"subtotal",
"tax_total",
"shipping_total",
"discount_total",
"total",
],
relations: ["shipping_address", "items", "payments"],
})
.registerCartCompletion(swapId)
swap = await swapService
.withTransaction(manager)
.retrieve(swap.id, { relations: ["shipping_address"] })
return {
response_code: 200,
response_body: { data: order, type: "order" },
response_body: { data: swap, type: "swap" },
}
} else if (
error &&
error.code === MedusaError.Codes.INSUFFICIENT_INVENTORY
) {
return {
response_code: 409,
response_body: {
message: error.message,
type: error.type,
code: error.code,
},
} 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`
)
}
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
}
} 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"],
})
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" },
return {
response_code: 200,
response_body: { data: order, type: "order" },
}
}
)
if (error) {
inProgress = false
err = error
} else {
idempotencyKey = key
}
)
if (error) {
inProgress = false
err = error
} else {
idempotencyKey = key
break
}
break
}
case "finished": {
inProgress = false
break
}
case "finished": {
inProgress = false
break
}
default:
idempotencyKey = await idempotencyKeyService.update(
idempotencyKey.idempotency_key,
{
recovery_point: "finished",
response_code: 500,
response_body: { message: "Unknown recovery point" },
}
)
break
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
}
if (err) {
throw err
}
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
} catch (error) {
throw error
}
}

View File

@@ -70,70 +70,74 @@ export default async (req, res) => {
user_agent: req.get("user-agent"),
}
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
try {
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`
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,
})
})
)
}
regionId = regions[0].id
}
cart = await cartService.withTransaction(manager).retrieve(cart.id, {
select: defaultFields,
relations: defaultRelations,
})
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,
res.status(200).json({ cart })
})
res.status(200).json({ cart })
})
} catch (err) {
throw err
}
}

View File

@@ -38,34 +38,38 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
const manager = req.scope.resolve("manager")
const lineItemService = req.scope.resolve("lineItemService")
const cartService = req.scope.resolve("cartService")
try {
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,
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"],
})
await txCartService.addLineItem(id, line)
const updated = await txCartService.retrieve(id, {
relations: ["payment_sessions"],
if (updated.payment_sessions?.length) {
await txCartService.setPaymentSessions(id)
}
})
if (updated.payment_sessions?.length) {
await txCartService.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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -22,14 +22,18 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id } = req.params
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -23,27 +23,31 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, code } = req.params
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
try {
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 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 (updated.payment_sessions?.length) {
await cartService.withTransaction(m).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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -23,27 +23,31 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, line_id } = req.params
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
try {
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 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 (updated.payment_sessions?.length) {
await cartService.withTransaction(m).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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -23,13 +23,17 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id, provider_id } = req.params
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -22,29 +22,33 @@ import { defaultFields, defaultRelations } from "./"
export default async (req, res) => {
const { id } = req.params
const cartService = req.scope.resolve("cartService")
try {
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,26 +21,30 @@
export default async (req, res) => {
const { id, provider_id } = req.params
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -33,13 +33,17 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

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

View File

@@ -34,49 +34,53 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
const manager = req.scope.resolve("manager")
const cartService = req.scope.resolve("cartService")
try {
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 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 lineItemUpdate = {
variant_id: existing.variant.id,
region_id: cart.region_id,
quantity: value.quantity,
metadata: existing.metadata || {},
// 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)
}
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"],
})
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 })
const cart = await cartService.retrieve(id, {
select: defaultFields,
relations: defaultRelations,
})
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -14,13 +14,17 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}

View File

@@ -35,15 +35,19 @@ export default async (req, res) => {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}
const cartService = req.scope.resolve("cartService")
try {
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 })
res.status(200).json({ cart })
} catch (err) {
throw err
}
}