feat(medusa): Adds filtering to order listing for use in admin (#149)
This commit is contained in:
@@ -5,7 +5,7 @@ export default async (req, res) => {
|
|||||||
const orderService = req.scope.resolve("orderService")
|
const orderService = req.scope.resolve("orderService")
|
||||||
const queryBuilderService = req.scope.resolve("queryBuilderService")
|
const queryBuilderService = req.scope.resolve("queryBuilderService")
|
||||||
|
|
||||||
const query = queryBuilderService.buildQuery(req.query, [
|
let query = queryBuilderService.buildQuery(req.query, [
|
||||||
"display_id",
|
"display_id",
|
||||||
"email",
|
"email",
|
||||||
"status",
|
"status",
|
||||||
@@ -13,10 +13,55 @@ export default async (req, res) => {
|
|||||||
"payment_status",
|
"payment_status",
|
||||||
])
|
])
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit) || 0
|
const limit = parseInt(req.query.limit) || 50
|
||||||
const offset = parseInt(req.query.offset) || 0
|
const offset = parseInt(req.query.offset) || 0
|
||||||
|
|
||||||
let orders = await orderService.list(query, offset, limit)
|
let orders
|
||||||
|
|
||||||
|
// Temporary solution for admin tabs filtering
|
||||||
|
// Will be replaced in Mongo -> Postgres migration
|
||||||
|
if (req.query["status"]) {
|
||||||
|
if (req.query["status"] === "returns") {
|
||||||
|
query = {
|
||||||
|
"returns.status": "requested",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.query["status"] === "new") {
|
||||||
|
query = {
|
||||||
|
$or: [
|
||||||
|
{ fulfillment_status: { $ne: "shipped" } },
|
||||||
|
{ payment_status: { $ne: "captured" } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.query["status"] === "requires_action") {
|
||||||
|
query = {
|
||||||
|
$or: [
|
||||||
|
{ status: "requires_action" },
|
||||||
|
{ payment_status: "requires_action" },
|
||||||
|
{ fulfillment_status: "requires_action" },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.query["status"] === "swaps") {
|
||||||
|
const swapService = req.scope.resolve("swapService")
|
||||||
|
|
||||||
|
const swapsInProgress = await swapService.list({
|
||||||
|
fulfillment_status: { $ne: "shipped" },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (swapsInProgress.length) {
|
||||||
|
query = {
|
||||||
|
swaps: { $in: swapsInProgress.map(s => s._id.toString()) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
orders = await orderService.list(query, offset, limit)
|
||||||
|
|
||||||
let includeFields = []
|
let includeFields = []
|
||||||
if ("fields" in req.query) {
|
if ("fields" in req.query) {
|
||||||
|
|||||||
@@ -48,14 +48,16 @@ describe("POST /admin/products/:id/variants/:variantId", () => {
|
|||||||
expect(ProductVariantServiceMock.setCurrencyPrice).toHaveBeenCalledWith(
|
expect(ProductVariantServiceMock.setCurrencyPrice).toHaveBeenCalledWith(
|
||||||
IdMap.getId("variant1"),
|
IdMap.getId("variant1"),
|
||||||
"DKK",
|
"DKK",
|
||||||
100
|
100,
|
||||||
|
undefined
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(ProductVariantServiceMock.setRegionPrice).toHaveBeenCalledTimes(1)
|
expect(ProductVariantServiceMock.setRegionPrice).toHaveBeenCalledTimes(1)
|
||||||
expect(ProductVariantServiceMock.setRegionPrice).toHaveBeenCalledWith(
|
expect(ProductVariantServiceMock.setRegionPrice).toHaveBeenCalledWith(
|
||||||
IdMap.getId("variant1"),
|
IdMap.getId("variant1"),
|
||||||
IdMap.getId("region-fr"),
|
IdMap.getId("region-fr"),
|
||||||
100
|
100,
|
||||||
|
undefined
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,16 @@ class SwapService extends BaseService {
|
|||||||
this.eventBus_ = eventBusService
|
this.eventBus_ = eventBusService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} selector - the query object for find
|
||||||
|
* @return {Promise} the result of the find operation
|
||||||
|
*/
|
||||||
|
list(selector, offset, limit) {
|
||||||
|
return this.swapModel_
|
||||||
|
.find(selector, {}, offset, limit)
|
||||||
|
.sort({ created: -1 })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to validate user ids. Throws an error if the cast fails
|
* Used to validate user ids. Throws an error if the cast fails
|
||||||
* @param {string} rawId - the raw user id to validate.
|
* @param {string} rawId - the raw user id to validate.
|
||||||
|
|||||||
+894
-16
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user