fix: make packages/medusa/src/api/routes/admin/orders pass eslint (#649)
This commit is contained in:
1 parent
ce4d3616d7
commit
dc8821095c
30 files changed
+39
-192
No files matched your search
@@ -27,7 +27,6 @@
|
||||
/packages/medusa/src/api/routes/admin/auth
|
||||
/packages/medusa/src/api/routes/admin/collections
|
||||
/packages/medusa/src/api/routes/admin/notes
|
||||
/packages/medusa/src/api/routes/admin/orders
|
||||
/packages/medusa/src/api/routes/admin/store
|
||||
/packages/medusa/src/api/routes/store/carts
|
||||
/packages/medusa/src/api/routes/store/return-reasons
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { defaultFields, defaultRelations } from "./"
|
||||
|
||||
@@ -28,15 +27,9 @@ export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.integer()
|
||||
.allow(0)
|
||||
.required(),
|
||||
price: Validator.number().integer().integer().allow(0).required(),
|
||||
option_id: Validator.string().required(),
|
||||
data: Validator.object()
|
||||
.optional()
|
||||
.default({}),
|
||||
data: Validator.object().optional().default({}),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -44,7 +37,6 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.addShippingMethod(id, value.option_id, value.data, {
|
||||
@@ -57,7 +49,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.archive(id)
|
||||
@@ -11,7 +10,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import { defaultRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, claim_id } = req.params
|
||||
|
||||
try {
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
@@ -45,7 +44,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import { defaultRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, claim_id, fulfillment_id } = req.params
|
||||
|
||||
try {
|
||||
const fulfillmentService = req.scope.resolve("fulfillmentService")
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
@@ -55,7 +54,4 @@ export default async (req, res) => {
|
||||
relations: defaultRelations,
|
||||
})
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import { defaultRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, swap_id, fulfillment_id } = req.params
|
||||
|
||||
try {
|
||||
const fulfillmentService = req.scope.resolve("fulfillmentService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
@@ -56,7 +55,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import { defaultRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, fulfillment_id } = req.params
|
||||
|
||||
try {
|
||||
const fulfillmentService = req.scope.resolve("fulfillmentService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
@@ -45,7 +44,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import { defaultFields, defaultRelations } from "."
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
await orderService.cancel(id)
|
||||
|
||||
@@ -32,7 +31,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import { defaultRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, swap_id } = req.params
|
||||
|
||||
try {
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
@@ -45,7 +44,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import { defaultRelations, defaultFields } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.capturePayment(id)
|
||||
@@ -33,7 +32,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.completeOrder(id)
|
||||
@@ -11,7 +10,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
fulfillment_id: Validator.string().required(),
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
tracking_numbers: Validator.array().items(Validator.string()).optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -49,14 +47,13 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
|
||||
await claimService.createShipment(
|
||||
claim_id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||
value.tracking_numbers.map((n) => ({ tracking_number: n }))
|
||||
)
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
@@ -65,7 +62,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -112,9 +112,7 @@ import { defaultRelations, defaultFields } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
const schema = Validator.object().keys({
|
||||
type: Validator.string()
|
||||
.valid("replace", "refund")
|
||||
.required(),
|
||||
type: Validator.string().valid("replace", "refund").required(),
|
||||
claim_items: Validator.array()
|
||||
.items({
|
||||
item_id: Validator.string().required(),
|
||||
@@ -133,9 +131,7 @@ export default async (req, res) => {
|
||||
return_shipping: Validator.object()
|
||||
.keys({
|
||||
option_id: Validator.string().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
price: Validator.number().integer().optional(),
|
||||
})
|
||||
.optional(),
|
||||
additional_items: Validator.array()
|
||||
@@ -148,14 +144,10 @@ export default async (req, res) => {
|
||||
.items({
|
||||
id: Validator.string().optional(),
|
||||
option_id: Validator.string().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
price: Validator.number().integer().optional(),
|
||||
})
|
||||
.optional(),
|
||||
refund_amount: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
refund_amount: Validator.number().integer().optional(),
|
||||
shipping_address: Validator.object().optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
@@ -185,7 +177,6 @@ export default async (req, res) => {
|
||||
res.setHeader("Access-Control-Expose-Headers", "Idempotency-Key")
|
||||
res.setHeader("Idempotency-Key", idempotencyKey.idempotency_key)
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
const returnService = req.scope.resolve("returnService")
|
||||
@@ -198,7 +189,7 @@ export default async (req, res) => {
|
||||
case "started": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
const order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
@@ -241,7 +232,7 @@ export default async (req, res) => {
|
||||
case "claim_created": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
let claim = await claimService.withTransaction(manager).list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
@@ -279,7 +270,7 @@ export default async (req, res) => {
|
||||
case "refund_handled": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
let order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
@@ -354,7 +345,4 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,6 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createFulfillment(id, value.items, {
|
||||
@@ -75,7 +74,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ import { MedusaError, Validator } from "medusa-core-utils"
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
status: Validator.string().optional(),
|
||||
email: Validator.string()
|
||||
.email()
|
||||
.required(),
|
||||
email: Validator.string().email().required(),
|
||||
billing_address: Validator.address().required(),
|
||||
shipping_address: Validator.address().required(),
|
||||
items: Validator.array().required(),
|
||||
@@ -36,13 +34,9 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
let order = await orderService.create(value)
|
||||
order = await orderService.decorate(order, [], ["region"])
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
fulfillment_id: Validator.string().required(),
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
tracking_numbers: Validator.array().items(Validator.string()).optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
@@ -52,13 +50,12 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createShipment(
|
||||
id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
value.tracking_numbers.map((n) => ({ tracking_number: n })),
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
@@ -68,7 +65,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
fulfillment_id: Validator.string().required(),
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
tracking_numbers: Validator.array().items(Validator.string()).optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
@@ -53,14 +51,13 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
|
||||
await swapService.createShipment(
|
||||
swap_id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers.map(n => ({ tracking_number: n })),
|
||||
value.tracking_numbers.map((n) => ({ tracking_number: n })),
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
|
||||
@@ -70,7 +67,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -87,9 +87,7 @@ export default async (req, res) => {
|
||||
return_shipping: Validator.object()
|
||||
.keys({
|
||||
option_id: Validator.string().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
price: Validator.number().integer().optional(),
|
||||
})
|
||||
.optional(),
|
||||
additional_items: Validator.array().items({
|
||||
@@ -131,7 +129,6 @@ export default async (req, res) => {
|
||||
res.setHeader("Access-Control-Expose-Headers", "Idempotency-Key")
|
||||
res.setHeader("Idempotency-Key", idempotencyKey.idempotency_key)
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const returnService = req.scope.resolve("returnService")
|
||||
@@ -144,7 +141,7 @@ export default async (req, res) => {
|
||||
case "started": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
const order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
@@ -173,9 +170,7 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.retrieveBySwap(swap.id)
|
||||
|
||||
await returnService
|
||||
.withTransaction(manager)
|
||||
.fulfill(returnOrder.id)
|
||||
await returnService.withTransaction(manager).fulfill(returnOrder.id)
|
||||
|
||||
return {
|
||||
recovery_point: "swap_created",
|
||||
@@ -195,7 +190,7 @@ export default async (req, res) => {
|
||||
case "swap_created": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
const swaps = await swapService.list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
@@ -251,7 +246,4 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
res.status(idempotencyKey.response_code).json(idempotencyKey.response_body)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@
|
||||
export default async (req, res) => {
|
||||
const { id, key } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.deleteMetadata(id, key)
|
||||
@@ -31,7 +30,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -45,12 +45,11 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
await claimService.withTransaction(manager).createFulfillment(claim_id, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
@@ -63,7 +62,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -45,12 +45,11 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
await swapService.withTransaction(manager).createFulfillment(swap_id, {
|
||||
metadata: value.metadata,
|
||||
no_notification: value.no_notification,
|
||||
@@ -63,7 +62,4 @@ export default async (req, res) => {
|
||||
|
||||
res.status(200).json({ order })
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import { defaultRelations, defaultFields } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
@@ -31,7 +30,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app) => {
|
||||
app.use("/orders", route)
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,13 +30,12 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
const limit = parseInt(req.query.limit) || 50
|
||||
const offset = parseInt(req.query.offset) || 0
|
||||
|
||||
let selector = {}
|
||||
const selector = {}
|
||||
|
||||
if ("q" in req.query) {
|
||||
selector.q = req.query.q
|
||||
@@ -68,20 +67,14 @@ export default async (req, res) => {
|
||||
order: { created_at: "DESC" },
|
||||
}
|
||||
|
||||
const [orders, count] = await orderService.listAndCount(
|
||||
selector,
|
||||
listConfig
|
||||
)
|
||||
const [orders, count] = await orderService.listAndCount(selector, listConfig)
|
||||
|
||||
let data = orders
|
||||
|
||||
const fields = [...includeFields, ...expandFields]
|
||||
if (fields.length) {
|
||||
data = orders.map(o => _.pick(o, fields))
|
||||
data = orders.map((o) => _.pick(o, fields))
|
||||
}
|
||||
|
||||
res.json({ orders: data, count, offset, limit })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,11 @@ import { defaultFields, defaultRelations } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id, swap_id } = req.params
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
await swapService.withTransaction(manager).processDifference(swap_id)
|
||||
|
||||
const order = await orderService.withTransaction(manager).retrieve(id, {
|
||||
@@ -38,7 +37,4 @@ export default async (req, res) => {
|
||||
|
||||
res.json({ order })
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -54,12 +54,11 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const swapService = req.scope.resolve("swapService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
await swapService
|
||||
.withTransaction(manager)
|
||||
.receiveReturn(swap_id, value.items)
|
||||
@@ -75,7 +74,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -43,13 +43,9 @@ import { defaultRelations, defaultFields } from "./"
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
const schema = Validator.object().keys({
|
||||
amount: Validator.number()
|
||||
.integer()
|
||||
.required(),
|
||||
amount: Validator.number().integer().required(),
|
||||
reason: Validator.string().required(),
|
||||
note: Validator.string()
|
||||
.allow("")
|
||||
.optional(),
|
||||
note: Validator.string().allow("").optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
})
|
||||
|
||||
@@ -59,16 +55,11 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.createRefund(
|
||||
id,
|
||||
value.amount,
|
||||
value.reason,
|
||||
value.note,
|
||||
{ no_notification: value.no_notification }
|
||||
)
|
||||
await orderService.createRefund(id, value.amount, value.reason, value.note, {
|
||||
no_notification: value.no_notification,
|
||||
})
|
||||
|
||||
const order = await orderService.retrieve(id, {
|
||||
select: defaultFields,
|
||||
@@ -76,7 +67,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -76,16 +76,12 @@ export default async (req, res) => {
|
||||
return_shipping: Validator.object()
|
||||
.keys({
|
||||
option_id: Validator.string().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
price: Validator.number().integer().optional(),
|
||||
})
|
||||
.optional(),
|
||||
receive_now: Validator.boolean().default(false),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
refund: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
refund: Validator.number().integer().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -126,7 +122,7 @@ export default async (req, res) => {
|
||||
case "started": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
const returnObj = {
|
||||
order_id: id,
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
@@ -145,7 +141,7 @@ export default async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
let order = await orderService
|
||||
const order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id)
|
||||
|
||||
@@ -191,7 +187,7 @@ export default async (req, res) => {
|
||||
case "return_requested": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
let order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, { relations: ["returns"] })
|
||||
|
||||
@@ -104,9 +104,7 @@ export default async (req, res) => {
|
||||
.items({
|
||||
id: Validator.string().optional(),
|
||||
option_id: Validator.string().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.optional(),
|
||||
price: Validator.number().integer().optional(),
|
||||
})
|
||||
.optional(),
|
||||
no_notification: Validator.boolean().optional(),
|
||||
@@ -118,7 +116,6 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
const claimService = req.scope.resolve("claimService")
|
||||
|
||||
@@ -130,7 +127,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ order: data })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
await orderService.update(id, value)
|
||||
@@ -42,7 +41,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user