Fix linting errors in admin/draft-orders (#676)
This commit is contained in:
1 parent
748270a75d
commit
c648a3c960
11 files changed
+17
-70
No files matched your search
@@ -26,7 +26,6 @@
|
||||
/packages/medusa/src/api/routes/admin/apps
|
||||
/packages/medusa/src/api/routes/admin/auth
|
||||
/packages/medusa/src/api/routes/admin/collections
|
||||
/packages/medusa/src/api/routes/admin/draft-orders
|
||||
/packages/medusa/src/api/routes/admin/notes
|
||||
/packages/medusa/src/api/routes/admin/orders
|
||||
/packages/medusa/src/api/routes/admin/return-reasons
|
||||
|
||||
@@ -98,23 +98,15 @@ import { defaultFields, defaultRelations } from "."
|
||||
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
status: Validator.string()
|
||||
.valid("open", "completed")
|
||||
.optional(),
|
||||
email: Validator.string()
|
||||
.email()
|
||||
.required(),
|
||||
status: Validator.string().valid("open", "completed").optional(),
|
||||
email: Validator.string().email().required(),
|
||||
billing_address: Validator.address().optional(),
|
||||
shipping_address: Validator.address().optional(),
|
||||
items: Validator.array()
|
||||
.items({
|
||||
variant_id: Validator.string()
|
||||
.optional()
|
||||
.allow(""),
|
||||
variant_id: Validator.string().optional().allow(""),
|
||||
unit_price: Validator.number().optional(),
|
||||
title: Validator.string()
|
||||
.optional()
|
||||
.allow(""),
|
||||
title: Validator.string().optional().allow(""),
|
||||
quantity: Validator.number().required(),
|
||||
metadata: Validator.object().default({}),
|
||||
})
|
||||
@@ -131,11 +123,7 @@ export default async (req, res) => {
|
||||
.items({
|
||||
option_id: Validator.string().required(),
|
||||
data: Validator.object().optional(),
|
||||
price: Validator.number()
|
||||
.integer()
|
||||
.integer()
|
||||
.allow(0)
|
||||
.optional(),
|
||||
price: Validator.number().integer().integer().allow(0).optional(),
|
||||
})
|
||||
.required(),
|
||||
metadata: Validator.object().optional(),
|
||||
@@ -148,7 +136,6 @@ export default async (req, res) => {
|
||||
|
||||
value = transformIdableFields(value, ["shipping_address", "billing_address"])
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
let draftOrder = await draftOrderService.create(value)
|
||||
|
||||
@@ -158,7 +145,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -55,13 +55,12 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
const lineItemService = req.scope.resolve("lineItemService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
const draftOrder = await draftOrderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, { select: defaultFields, relations: ["cart"] })
|
||||
@@ -105,7 +104,4 @@ export default async (req, res) => {
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,12 @@
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
await draftOrderService.delete(id)
|
||||
|
||||
res.json({
|
||||
id,
|
||||
object: "draft-order",
|
||||
deleted: true,
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { defaultCartFields, defaultCartRelations, defaultFields } from "."
|
||||
|
||||
/**
|
||||
@@ -25,12 +25,11 @@ import { defaultCartFields, defaultCartRelations, defaultFields } from "."
|
||||
export default async (req, res) => {
|
||||
const { id, line_id } = req.params
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
const draftOrder = await draftOrderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, { select: defaultFields })
|
||||
@@ -55,7 +54,4 @@ export default async (req, res) => {
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
@@ -43,7 +42,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.json({ draft_order: draftOrder })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app) => {
|
||||
app.use("/draft-orders", route)
|
||||
|
||||
route.get("/", middlewares.wrap(require("./list-draft-orders").default))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from "lodash"
|
||||
import { defaultFields, defaultRelations } from "./"
|
||||
|
||||
/**
|
||||
@@ -20,13 +19,12 @@ import { defaultFields, defaultRelations } from "./"
|
||||
*/
|
||||
|
||||
export default async (req, res) => {
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
|
||||
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
|
||||
@@ -46,7 +44,4 @@ export default async (req, res) => {
|
||||
)
|
||||
|
||||
res.json({ draft_orders: draftOrders, count, offset, limit })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const paymentProviderService = req.scope.resolve("paymentProviderService")
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
@@ -34,7 +33,7 @@ export default async (req, res) => {
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
let result
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
const draftOrder = await draftOrderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id)
|
||||
@@ -63,9 +62,7 @@ export default async (req, res) => {
|
||||
|
||||
await cartService.withTransaction(manager).authorizePayment(cart.id)
|
||||
|
||||
result = await orderService
|
||||
.withTransaction(manager)
|
||||
.createFromCart(cart.id)
|
||||
result = await orderService.withTransaction(manager).createFromCart(cart.id)
|
||||
|
||||
await draftOrderService
|
||||
.withTransaction(manager)
|
||||
@@ -78,7 +75,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
import { defaultCartFields, defaultCartRelations, defaultFields } from "."
|
||||
import { defaultCartFields, defaultCartRelations } from "."
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/draft-orders/{id}
|
||||
@@ -60,9 +60,7 @@ export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
region_id: Validator.string().optional(),
|
||||
country_code: Validator.string().optional(),
|
||||
email: Validator.string()
|
||||
.email()
|
||||
.optional(),
|
||||
email: Validator.string().email().optional(),
|
||||
billing_address: Validator.object().optional(),
|
||||
shipping_address: Validator.object().optional(),
|
||||
discounts: Validator.array()
|
||||
@@ -79,7 +77,6 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
|
||||
@@ -107,7 +104,4 @@ export default async (req, res) => {
|
||||
})
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -51,12 +51,11 @@ export default async (req, res) => {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const draftOrderService = req.scope.resolve("draftOrderService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
const entityManager = req.scope.resolve("manager")
|
||||
|
||||
await entityManager.transaction(async manager => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
const draftOrder = await draftOrderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
@@ -76,7 +75,7 @@ export default async (req, res) => {
|
||||
.withTransaction(manager)
|
||||
.removeLineItem(draftOrder.cart.id, line_id)
|
||||
} else {
|
||||
const existing = draftOrder.cart.items.find(i => i.id === line_id)
|
||||
const existing = draftOrder.cart.items.find((i) => i.id === line_id)
|
||||
|
||||
if (!existing) {
|
||||
throw new MedusaError(
|
||||
@@ -108,7 +107,4 @@ export default async (req, res) => {
|
||||
|
||||
res.status(200).json({ draft_order: draftOrder })
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user