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