Skip to content

Commit

Permalink
fix(medusa): plus sign to space (#8454)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues authored Aug 6, 2024
1 parent 0ec1d98 commit 8700896
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ medusaIntegrationTestRunner({

const variants = (
await api.get(
`/admin/products/${product.id}/variants?fields=%2Binventory_quantity`,
`/admin/products/${product.id}/variants?fields=+inventory_quantity`,
adminHeaders
)
).data.variants
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/modules/__tests__/order/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ medusaIntegrationTestRunner({
const response = await api.get(
"/admin/orders/" +
created.id +
"?fields=%2Braw_total,%2Braw_subtotal,%2Braw_discount_total",
"?fields=+raw_total,+raw_subtotal,+raw_discount_total",
adminHeaders
)

Expand Down
10 changes: 6 additions & 4 deletions packages/medusa/src/utils/get-query-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestQueryFields } from "@medusajs/types"
import {
getSetDifference,
isDefined,
Expand All @@ -6,7 +7,6 @@ import {
stringToSelectRelationObject,
} from "@medusajs/utils"
import { pick } from "lodash"
import { RequestQueryFields } from "@medusajs/types"
import { FindConfig, QueryConfig } from "../types/common"

export function pickByConfig<TModel>(
Expand Down Expand Up @@ -60,15 +60,17 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
return !(
field.startsWith("-") ||
field.startsWith("+") ||
field.startsWith(" ") ||
field.startsWith("*")
)
})

if (shouldReplaceDefaultFields) {
allFields = new Set(customFields.map((f) => f.replace(/^[+-]/, "")))
allFields = new Set(customFields.map((f) => f.replace(/^[+ -]/, "")))
} else {
customFields.forEach((field) => {
if (field.startsWith("+")) {
allFields.add(field.replace(/^\+/, ""))
if (field.startsWith("+") || field.startsWith(" ")) {
allFields.add(field.trim().replace(/^\+/, ""))
} else if (field.startsWith("-")) {
allFields.delete(field.replace(/^-/, ""))
} else {
Expand Down

0 comments on commit 8700896

Please sign in to comment.