fix(medeusa): Transform query includes options should only be added to allowed props if there is already at least one allowed props (#3362)
**What** when `fields` only contain includes options, it should return the entire object plus the include options. If the fields contains the included options + other fields, it should only return the requested fields + the included options
This commit is contained in:
1 parent
15f47baf56
commit
33c6ccf059
6 files changed
+160
-83
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medeusa): Transform query includes options should only be added to allowed props if there is already at least one allowed props
|
||||||
@@ -2443,11 +2443,90 @@ describe("/admin/orders", () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(order.status).toEqual(200)
|
expect(order.status).toEqual(200)
|
||||||
expect(order.data.order).toEqual(
|
// id + totals + region relation
|
||||||
expect.objectContaining({
|
expect(order.data.order).toEqual({
|
||||||
id: "test-order",
|
id: "test-order",
|
||||||
})
|
region: expect.any(Object),
|
||||||
|
shipping_total: 1000,
|
||||||
|
discount_total: 800,
|
||||||
|
tax_total: 0,
|
||||||
|
refunded_total: 0,
|
||||||
|
total: 8200,
|
||||||
|
subtotal: 8000,
|
||||||
|
paid_total: 0,
|
||||||
|
refundable_amount: 0,
|
||||||
|
gift_card_total: 0,
|
||||||
|
gift_card_tax_total: 0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("retrieves an order with expand returnable_items only should return the entire object and only returnable_items as relation", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const order = await api.get(
|
||||||
|
`/admin/orders/${testOrderId}?expand=returnable_items`,
|
||||||
|
adminReqConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
expect(order.status).toEqual(200)
|
||||||
|
// all order properties + totals + returnable_items relation
|
||||||
|
expect(order.data.order).toEqual({
|
||||||
|
id: "test-order",
|
||||||
|
status: "pending",
|
||||||
|
fulfillment_status: "fulfilled",
|
||||||
|
payment_status: "captured",
|
||||||
|
display_id: expect.any(Number),
|
||||||
|
cart_id: null,
|
||||||
|
draft_order_id: null,
|
||||||
|
customer_id: "test-customer",
|
||||||
|
email: "test@email.com",
|
||||||
|
region_id: "test-region",
|
||||||
|
currency_code: "usd",
|
||||||
|
tax_rate: 0,
|
||||||
|
canceled_at: null,
|
||||||
|
created_at: expect.any(String),
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
metadata: null,
|
||||||
|
no_notification: null,
|
||||||
|
sales_channel_id: null,
|
||||||
|
returnable_items: expect.any(Array),
|
||||||
|
shipping_total: 1000,
|
||||||
|
discount_total: 800,
|
||||||
|
tax_total: 0,
|
||||||
|
refunded_total: 0,
|
||||||
|
total: 8200,
|
||||||
|
subtotal: 8000,
|
||||||
|
paid_total: 10000,
|
||||||
|
refundable_amount: 10000,
|
||||||
|
gift_card_total: 0,
|
||||||
|
gift_card_tax_total: 0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("retrieves an order with expand returnable_items and field id should return the id and the retunable_items", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const order = await api.get(
|
||||||
|
`/admin/orders/${testOrderId}?expand=returnable_items&fields=id`,
|
||||||
|
adminReqConfig
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(order.status).toEqual(200)
|
||||||
|
// id + totals + returnable_items relation
|
||||||
|
expect(order.data.order).toEqual({
|
||||||
|
id: "test-order",
|
||||||
|
returnable_items: expect.any(Array),
|
||||||
|
shipping_total: 1000,
|
||||||
|
discount_total: 800,
|
||||||
|
tax_total: 0,
|
||||||
|
refunded_total: 0,
|
||||||
|
total: 8200,
|
||||||
|
subtotal: 8000,
|
||||||
|
paid_total: 10000,
|
||||||
|
refundable_amount: 10000,
|
||||||
|
gift_card_total: 0,
|
||||||
|
gift_card_tax_total: 0,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("retrieves an order should include the items totals", async () => {
|
it("retrieves an order should include the items totals", async () => {
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ describe("/admin/swaps", () => {
|
|||||||
|
|
||||||
// ********* CREATE SWAP *********
|
// ********* CREATE SWAP *********
|
||||||
const createSwap = await api.post(
|
const createSwap = await api.post(
|
||||||
`/admin/orders/${completedOrder.data.data.id}/swaps?fields=returnable_items`,
|
`/admin/orders/${completedOrder.data.data.id}/swaps`,
|
||||||
{
|
{
|
||||||
return_items: [
|
return_items: [
|
||||||
{
|
{
|
||||||
@@ -318,13 +318,6 @@ describe("/admin/swaps", () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(createSwap.data.order.returnable_items).toHaveLength(1)
|
|
||||||
expect(createSwap.data.order.returnable_items[0]).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
id: "line-item",
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
let swap = createSwap.data.order.swaps[0]
|
let swap = createSwap.data.order.swaps[0]
|
||||||
|
|
||||||
// ********* PREPARE SWAP CART *********
|
// ********* PREPARE SWAP CART *********
|
||||||
|
|||||||
@@ -1,38 +1,37 @@
|
|||||||
import { NextFunction, Request, Response } from "express"
|
import { NextFunction, Request, Response } from "express"
|
||||||
import { Order } from "../../models"
|
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the includes options from the fields query param.
|
* Retrieve the includes options from the fields query param.
|
||||||
* If the include option is present then assigned it to includes on req
|
* If the include option is present then assigned it to includes on req
|
||||||
* @param allowedIncludesFields The list of fields that can be passed and assign to req.includes
|
* @param allowedIncludes The list of fields that can be passed and assign to req.includes
|
||||||
* @param expectedIncludesFields The list of fields that the consumer can pass to the end point using this middleware. It is a subset of `allowedIncludesFields`
|
* @param expectedIncludes The list of fields that the consumer can pass to the end point using this middleware. It is a subset of `allowedIncludes`
|
||||||
*/
|
*/
|
||||||
export function transformIncludesOptions(
|
export function transformIncludesOptions(
|
||||||
allowedIncludesFields: string[] = [],
|
allowedIncludes: string[] = [],
|
||||||
expectedIncludesFields: string[] = []
|
expectedIncludes: string[] = []
|
||||||
) {
|
) {
|
||||||
return (req: Request, res: Response, next: NextFunction): void => {
|
return (req: Request, res: Response, next: NextFunction): void => {
|
||||||
if (!allowedIncludesFields.length || !req.query.fields) {
|
if (!allowedIncludes.length || !req.query.expand) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
const fields = (req.query.fields as string).split(",") ?? []
|
const expand = (req.query.expand as string).split(",") ?? []
|
||||||
|
|
||||||
for (const includesField of allowedIncludesFields) {
|
for (const includes of allowedIncludes) {
|
||||||
const fieldIndex = fields.indexOf(includesField as keyof Order) ?? -1
|
const fieldIndex = expand.indexOf(includes) ?? -1
|
||||||
|
|
||||||
const isPresent = fieldIndex !== -1
|
const isPresent = fieldIndex !== -1
|
||||||
|
|
||||||
if (isPresent) {
|
if (isPresent) {
|
||||||
fields.splice(fieldIndex, 1)
|
expand.splice(fieldIndex, 1)
|
||||||
|
|
||||||
if (!expectedIncludesFields.includes(includesField)) {
|
if (!expectedIncludes.includes(includes)) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.INVALID_DATA,
|
MedusaError.Types.INVALID_DATA,
|
||||||
`The field "${includesField}" is not supported by this end point. ${
|
`The field "${includes}" is not supported by this end point. ${
|
||||||
expectedIncludesFields.length
|
expectedIncludes.length
|
||||||
? `The includes fields can be one of entity properties or in [${expectedIncludesFields.join(
|
? `The includes fields can be one of entity properties or in [${expectedIncludes.join(
|
||||||
", "
|
", "
|
||||||
)}]`
|
)}]`
|
||||||
: ""
|
: ""
|
||||||
@@ -41,15 +40,15 @@ export function transformIncludesOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.includes = req.includes ?? {}
|
req.includes = req.includes ?? {}
|
||||||
req.includes[includesField] = true
|
req.includes[includes] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.query.fields) {
|
if (req.query.expand) {
|
||||||
if (fields.length) {
|
if (expand.length) {
|
||||||
req.query.fields = fields.join(",")
|
req.query.expand = expand.join(",")
|
||||||
} else {
|
} else {
|
||||||
delete req.query.fields
|
delete req.query.expand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ function attachListOrRetrieveConfig<TEntity extends BaseEntity>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Build the store allowed props based on the custom fields query params, the defaults and the includes options.
|
* Build the store allowed props based on the custom fields query params, the allowed props config and the includes options.
|
||||||
* This can be used later with `cleanResponseData` in order to clean up the returned objects to the client.
|
* This can be used later with `cleanResponseData` in order to clean up the returned objects to the client.
|
||||||
* @param queryConfig
|
* @param queryConfig
|
||||||
* @param validated
|
* @param validated
|
||||||
@@ -141,19 +141,17 @@ function getStoreAllowedProperties<TEntity extends BaseEntity>(
|
|||||||
queryConfig?: QueryConfig<TEntity>
|
queryConfig?: QueryConfig<TEntity>
|
||||||
): string[] {
|
): string[] {
|
||||||
const allowed: string[] = []
|
const allowed: string[] = []
|
||||||
allowed.push(
|
|
||||||
...(validated.fields
|
|
||||||
? validated.fields.split(",")
|
|
||||||
: queryConfig?.allowedFields || []),
|
|
||||||
...(validated.expand
|
|
||||||
? validated.expand.split(",")
|
|
||||||
: queryConfig?.allowedRelations || [])
|
|
||||||
)
|
|
||||||
|
|
||||||
const includeKeys = Object.keys(includesOptions)
|
const includeKeys = Object.keys(includesOptions)
|
||||||
if (includeKeys) {
|
const fields = validated.fields
|
||||||
allowed.push(...includeKeys)
|
? validated.fields?.split(",")
|
||||||
}
|
: queryConfig?.allowedFields || []
|
||||||
|
const expand =
|
||||||
|
validated.expand || includeKeys.length
|
||||||
|
? [...(validated.expand?.split(",") || []), ...includeKeys]
|
||||||
|
: queryConfig?.allowedRelations || []
|
||||||
|
|
||||||
|
allowed.push(...fields, ...expand)
|
||||||
|
|
||||||
return allowed
|
return allowed
|
||||||
}
|
}
|
||||||
@@ -171,16 +169,18 @@ function getAllowedProperties<TEntity extends BaseEntity>(
|
|||||||
includesOptions: Record<string, boolean>,
|
includesOptions: Record<string, boolean>,
|
||||||
queryConfig?: QueryConfig<TEntity>
|
queryConfig?: QueryConfig<TEntity>
|
||||||
): string[] {
|
): string[] {
|
||||||
const allowed: string[] = []
|
const allowed: (string | keyof TEntity)[] = []
|
||||||
allowed.push(
|
|
||||||
...(validated.fields?.split(",") ?? []),
|
|
||||||
...(validated.expand?.split(",") ?? [])
|
|
||||||
)
|
|
||||||
|
|
||||||
const includeKeys = Object.keys(includesOptions)
|
const includeKeys = Object.keys(includesOptions)
|
||||||
if (includeKeys) {
|
const fields = validated.fields
|
||||||
allowed.push(...includeKeys)
|
? validated.fields?.split(",")
|
||||||
}
|
: queryConfig?.defaultFields || []
|
||||||
|
const expand =
|
||||||
|
validated.expand || includeKeys.length
|
||||||
|
? [...(validated.expand?.split(",") || []), ...includeKeys]
|
||||||
|
: queryConfig?.defaultRelations || []
|
||||||
|
|
||||||
return allowed
|
allowed.push(...fields, ...expand)
|
||||||
|
|
||||||
|
return allowed as string[]
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.get(
|
route.get(
|
||||||
"/",
|
"/",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminGetOrdersParams, {
|
transformQuery(AdminGetOrdersParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultAdminOrdersFields,
|
defaultFields: defaultAdminOrdersFields,
|
||||||
@@ -105,8 +105,8 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.get(
|
route.get(
|
||||||
"/:id",
|
"/:id",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields, [
|
transformIncludesOptions(allowedOrderIncludes, [
|
||||||
AvailableOrderIncludesFields.RETURNABLE_ITEMS,
|
AvailableOrderIncludes.RETURNABLE_ITEMS,
|
||||||
]),
|
]),
|
||||||
transformQuery(AdminPostOrdersOrderParams, {
|
transformQuery(AdminPostOrdersOrderParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -121,7 +121,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id",
|
"/:id",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderReq),
|
transformBody(AdminPostOrdersOrderReq),
|
||||||
transformQuery(FindParams, {
|
transformQuery(FindParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -136,7 +136,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/complete",
|
"/:id/complete",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderCompleteParams, {
|
transformQuery(AdminPostOrdersOrderCompleteParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -150,7 +150,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/refund",
|
"/:id/refund",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderRefundsReq),
|
transformBody(AdminPostOrdersOrderRefundsReq),
|
||||||
transformQuery(AdminPostOrdersOrderRefundsParams, {
|
transformQuery(AdminPostOrdersOrderRefundsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -165,7 +165,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/capture",
|
"/:id/capture",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderCaptureParams, {
|
transformQuery(AdminPostOrdersOrderCaptureParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -179,7 +179,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/fulfillment",
|
"/:id/fulfillment",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderFulfillmentsReq),
|
transformBody(AdminPostOrdersOrderFulfillmentsReq),
|
||||||
transformQuery(AdminPostOrdersOrderFulfillmentsParams, {
|
transformQuery(AdminPostOrdersOrderFulfillmentsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -194,7 +194,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/fulfillments/:fulfillment_id/cancel",
|
"/:id/fulfillments/:fulfillment_id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderFulfillementsCancelParams, {
|
transformQuery(AdminPostOrdersOrderFulfillementsCancelParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -208,7 +208,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps/:swap_id/fulfillments/:fulfillment_id/cancel",
|
"/:id/swaps/:swap_id/fulfillments/:fulfillment_id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderSwapFulfillementsCancelParams, {
|
transformQuery(AdminPostOrdersOrderSwapFulfillementsCancelParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -222,7 +222,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims/:claim_id/fulfillments/:fulfillment_id/cancel",
|
"/:id/claims/:claim_id/fulfillments/:fulfillment_id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersClaimFulfillmentsCancelParams, {
|
transformQuery(AdminPostOrdersClaimFulfillmentsCancelParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -236,7 +236,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/shipment",
|
"/:id/shipment",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderShipmentReq),
|
transformBody(AdminPostOrdersOrderShipmentReq),
|
||||||
transformQuery(AdminPostOrdersOrderShipmentParams, {
|
transformQuery(AdminPostOrdersOrderShipmentParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -251,7 +251,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/return",
|
"/:id/return",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderReturnsReq),
|
transformBody(AdminPostOrdersOrderReturnsReq),
|
||||||
transformQuery(AdminPostOrdersOrderReturnsParams, {
|
transformQuery(AdminPostOrdersOrderReturnsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -266,7 +266,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/cancel",
|
"/:id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderCancel, {
|
transformQuery(AdminPostOrdersOrderCancel, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -280,7 +280,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/shipping-methods",
|
"/:id/shipping-methods",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderShippingMethodsReq),
|
transformBody(AdminPostOrdersOrderShippingMethodsReq),
|
||||||
transformQuery(AdminPostOrdersOrderShippingMethodsParams, {
|
transformQuery(AdminPostOrdersOrderShippingMethodsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -295,7 +295,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/archive",
|
"/:id/archive",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderArchiveParams, {
|
transformQuery(AdminPostOrdersOrderArchiveParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -309,8 +309,8 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps",
|
"/:id/swaps",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields, [
|
transformIncludesOptions(allowedOrderIncludes, [
|
||||||
AvailableOrderIncludesFields.RETURNABLE_ITEMS,
|
AvailableOrderIncludes.RETURNABLE_ITEMS,
|
||||||
]),
|
]),
|
||||||
transformBody(AdminPostOrdersOrderSwapsReq),
|
transformBody(AdminPostOrdersOrderSwapsReq),
|
||||||
transformQuery(AdminPostOrdersOrderSwapsParams, {
|
transformQuery(AdminPostOrdersOrderSwapsParams, {
|
||||||
@@ -326,7 +326,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps/:swap_id/cancel",
|
"/:id/swaps/:swap_id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersSwapCancelParams, {
|
transformQuery(AdminPostOrdersSwapCancelParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -340,7 +340,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps/:swap_id/fulfillments",
|
"/:id/swaps/:swap_id/fulfillments",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderSwapsSwapFulfillmentsParams, {
|
transformQuery(AdminPostOrdersOrderSwapsSwapFulfillmentsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -354,7 +354,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps/:swap_id/shipments",
|
"/:id/swaps/:swap_id/shipments",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderSwapsSwapShipmentsReq),
|
transformBody(AdminPostOrdersOrderSwapsSwapShipmentsReq),
|
||||||
transformQuery(AdminPostOrdersOrderSwapsSwapShipmentsParams, {
|
transformQuery(AdminPostOrdersOrderSwapsSwapShipmentsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -369,7 +369,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/swaps/:swap_id/process-payment",
|
"/:id/swaps/:swap_id/process-payment",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersOrderSwapsSwapProcessPaymentParams, {
|
transformQuery(AdminPostOrdersOrderSwapsSwapProcessPaymentParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -383,7 +383,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims",
|
"/:id/claims",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderClaimsReq),
|
transformBody(AdminPostOrdersOrderClaimsReq),
|
||||||
transformQuery(AdminPostOrdersOrderClaimsParams, {
|
transformQuery(AdminPostOrdersOrderClaimsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -398,7 +398,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims/:claim_id/cancel",
|
"/:id/claims/:claim_id/cancel",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformQuery(AdminPostOrdersClaimCancel, {
|
transformQuery(AdminPostOrdersClaimCancel, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
defaultFields: defaultFields,
|
defaultFields: defaultFields,
|
||||||
@@ -412,7 +412,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims/:claim_id",
|
"/:id/claims/:claim_id",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderClaimsClaimReq),
|
transformBody(AdminPostOrdersOrderClaimsClaimReq),
|
||||||
transformQuery(AdminPostOrdersOrderClaimsClaimParams, {
|
transformQuery(AdminPostOrdersOrderClaimsClaimParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -427,7 +427,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims/:claim_id/fulfillments",
|
"/:id/claims/:claim_id/fulfillments",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderClaimsClaimFulfillmentsReq),
|
transformBody(AdminPostOrdersOrderClaimsClaimFulfillmentsReq),
|
||||||
transformQuery(AdminPostOrdersOrderClaimsClaimFulfillmentsParams, {
|
transformQuery(AdminPostOrdersOrderClaimsClaimFulfillmentsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -442,7 +442,7 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
|||||||
*/
|
*/
|
||||||
route.post(
|
route.post(
|
||||||
"/:id/claims/:claim_id/shipments",
|
"/:id/claims/:claim_id/shipments",
|
||||||
transformIncludesOptions(allowedOrderIncludesFields),
|
transformIncludesOptions(allowedOrderIncludes),
|
||||||
transformBody(AdminPostOrdersOrderClaimsClaimShipmentsReq),
|
transformBody(AdminPostOrdersOrderClaimsClaimShipmentsReq),
|
||||||
transformQuery(AdminPostOrdersOrderClaimsClaimShipmentsParams, {
|
transformQuery(AdminPostOrdersOrderClaimsClaimShipmentsParams, {
|
||||||
defaultRelations: relations,
|
defaultRelations: relations,
|
||||||
@@ -525,6 +525,9 @@ export const defaultAdminOrdersRelations = [
|
|||||||
"discounts.rule",
|
"discounts.rule",
|
||||||
"shipping_methods",
|
"shipping_methods",
|
||||||
"payments",
|
"payments",
|
||||||
|
"items",
|
||||||
|
"refunds",
|
||||||
|
"region",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
"fulfillments.tracking_links",
|
"fulfillments.tracking_links",
|
||||||
"fulfillments.items",
|
"fulfillments.items",
|
||||||
@@ -603,13 +606,11 @@ export const filterableAdminOrdersFields = [
|
|||||||
"updated_at",
|
"updated_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const AvailableOrderIncludesFields = {
|
export const AvailableOrderIncludes = {
|
||||||
RETURNABLE_ITEMS: "returnable_items",
|
RETURNABLE_ITEMS: "returnable_items",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const allowedOrderIncludesFields = [
|
export const allowedOrderIncludes = [AvailableOrderIncludes.RETURNABLE_ITEMS]
|
||||||
AvailableOrderIncludesFields.RETURNABLE_ITEMS,
|
|
||||||
]
|
|
||||||
|
|
||||||
export * from "./add-shipping-method"
|
export * from "./add-shipping-method"
|
||||||
export * from "./archive-order"
|
export * from "./archive-order"
|
||||||
|
|||||||
Reference in new issue
Block a user