fix(modules-sdk): Remote Query "order" as config options (#6925)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/modules-sdk": patch
|
||||||
|
"@medusajs/currency": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Remote Query "order" as options
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
|
||||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
|
import { createAdminUser } from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
jest.setTimeout(50000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
@@ -41,6 +41,18 @@ medusaIntegrationTestRunner({
|
|||||||
listResp.data.currencies.find((c) => c.code === "aud")
|
listResp.data.currencies.find((c) => c.code === "aud")
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should correctly list currencies in the correct order", async () => {
|
||||||
|
const listResp = await api.get(
|
||||||
|
"/admin/currencies?order=-code",
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const first = listResp.data.currencies.shift()
|
||||||
|
expect(first).toEqual(
|
||||||
|
expect.objectContaining({ code: "zwl", name: "Zimbabwean Dollar" })
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -798,7 +798,7 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
|
|
||||||
response = await api.get(
|
response = await api.get(
|
||||||
`/admin/promotions/rule-value-options/rules/currency?limit=2`,
|
`/admin/promotions/rule-value-options/rules/currency?limit=2&order=name`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -806,14 +806,8 @@ medusaIntegrationTestRunner({
|
|||||||
expect(response.data.values.length).toEqual(2)
|
expect(response.data.values.length).toEqual(2)
|
||||||
expect(response.data.values).toEqual(
|
expect(response.data.values).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
{
|
{ label: "Afghan Afghani", value: "afn" },
|
||||||
label: "United Arab Emirates Dirham",
|
{ label: "Albanian Lek", value: "all" },
|
||||||
value: "aed",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Afghan Afghani",
|
|
||||||
value: "afn",
|
|
||||||
},
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -862,8 +856,8 @@ medusaIntegrationTestRunner({
|
|||||||
expect(response.data.values.length).toEqual(2)
|
expect(response.data.values.length).toEqual(2)
|
||||||
expect(response.data.values).toEqual(
|
expect(response.data.values).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
{ label: "Andorra", value: "ad" },
|
{ label: "Afghanistan", value: "af" },
|
||||||
{ label: "United Arab Emirates", value: "ae" },
|
{ label: "Albania", value: "al" },
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
{
|
{
|
||||||
"namespaces": [
|
"namespaces": ["public"],
|
||||||
"public"
|
|
||||||
],
|
|
||||||
"name": "public",
|
"name": "public",
|
||||||
"tables": [
|
"tables": [
|
||||||
{
|
{
|
||||||
@@ -70,6 +68,28 @@
|
|||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"mappedType": "json"
|
"mappedType": "json"
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "timestamptz",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": false,
|
||||||
|
"length": 6,
|
||||||
|
"default": "now()",
|
||||||
|
"mappedType": "datetime"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"name": "updated_at",
|
||||||
|
"type": "timestamptz",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": false,
|
||||||
|
"length": 6,
|
||||||
|
"default": "now()",
|
||||||
|
"mappedType": "datetime"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"name": "currency",
|
"name": "currency",
|
||||||
@@ -77,9 +97,7 @@
|
|||||||
"indexes": [
|
"indexes": [
|
||||||
{
|
{
|
||||||
"keyName": "currency_pkey",
|
"keyName": "currency_pkey",
|
||||||
"columnNames": [
|
"columnNames": ["code"],
|
||||||
"code"
|
|
||||||
],
|
|
||||||
"composite": false,
|
"composite": false,
|
||||||
"primary": true,
|
"primary": true,
|
||||||
"unique": true
|
"unique": true
|
||||||
|
|||||||
@@ -2,24 +2,27 @@ import { Migration } from "@mikro-orm/migrations"
|
|||||||
|
|
||||||
export class InitialSetup20240228133303 extends Migration {
|
export class InitialSetup20240228133303 extends Migration {
|
||||||
async up(): Promise<void> {
|
async up(): Promise<void> {
|
||||||
const currencyTables = await this.execute(
|
this.addSql(`
|
||||||
"select * from information_schema.tables where table_name = 'currency' and table_schema = 'public'"
|
create table if not exists "currency"
|
||||||
)
|
(
|
||||||
|
"code" text not null,
|
||||||
|
"symbol" text not null,
|
||||||
|
"symbol_native" text not null,
|
||||||
|
"decimal_digits" int not null default 0,
|
||||||
|
"rounding" numeric not null default 0,
|
||||||
|
"raw_rounding" jsonb not null,
|
||||||
|
"name" text not null,
|
||||||
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
constraint "currency_pkey" primary key ("code")
|
||||||
|
);
|
||||||
|
|
||||||
if (currencyTables.length > 0) {
|
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "created_at" TIMESTAMPTZ NOT NULL DEFAULT now();
|
||||||
// This is so we can still run the api tests, remove completely once that is not needed
|
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "updated_at" TIMESTAMPTZ NULL DEFAULT now();
|
||||||
this.addSql(
|
|
||||||
`alter table "currency" add column "decimal_digits" int not null default 0;`
|
|
||||||
)
|
|
||||||
this.addSql(
|
|
||||||
`alter table "currency" add column "rounding" numeric not null default 0;`
|
|
||||||
)
|
|
||||||
this.addSql(`alter table "currency" add column "raw_rounding" jsonb;`)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addSql(`create table if not exists "currency"
|
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "decimal_digits" int not null default 0;
|
||||||
("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null,
|
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "rounding" numeric not null default 0;
|
||||||
"decimal_digits" int not null default 0, "rounding" numeric not null default 0, "raw_rounding" jsonb not null,
|
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "raw_rounding" jsonb;
|
||||||
constraint "currency_pkey" primary key ("code"));`)
|
`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,21 @@ class Currency {
|
|||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
@Property({ columnType: "jsonb" })
|
||||||
raw_rounding: BigNumberRawValue
|
raw_rounding: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
onCreate: () => new Date(),
|
||||||
|
columnType: "timestamptz",
|
||||||
|
defaultRaw: "now()",
|
||||||
|
})
|
||||||
|
created_at: Date
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
onCreate: () => new Date(),
|
||||||
|
onUpdate: () => new Date(),
|
||||||
|
columnType: "timestamptz",
|
||||||
|
defaultRaw: "now()",
|
||||||
|
})
|
||||||
|
updated_at: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Currency
|
export default Currency
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { pick } from "lodash"
|
|
||||||
import { FindConfig, QueryConfig, RequestQueryFields } from "../types/common"
|
|
||||||
import { isDefined, MedusaError } from "medusa-core-utils"
|
|
||||||
import { BaseEntity } from "../interfaces"
|
|
||||||
import { getSetDifference, stringToSelectRelationObject } from "@medusajs/utils"
|
import { getSetDifference, stringToSelectRelationObject } from "@medusajs/utils"
|
||||||
|
import { pick } from "lodash"
|
||||||
|
import { MedusaError, isDefined } from "medusa-core-utils"
|
||||||
|
import { BaseEntity } from "../interfaces"
|
||||||
|
import { FindConfig, QueryConfig, RequestQueryFields } from "../types/common"
|
||||||
|
|
||||||
export function pickByConfig<TModel extends BaseEntity>(
|
export function pickByConfig<TModel extends BaseEntity>(
|
||||||
obj: TModel | TModel[],
|
obj: TModel | TModel[],
|
||||||
@@ -24,6 +24,8 @@ export function prepareListQuery<
|
|||||||
T extends RequestQueryFields,
|
T extends RequestQueryFields,
|
||||||
TEntity extends BaseEntity
|
TEntity extends BaseEntity
|
||||||
>(validated: T, queryConfig: QueryConfig<TEntity> = {}) {
|
>(validated: T, queryConfig: QueryConfig<TEntity> = {}) {
|
||||||
|
const isMedusaV2 = process.env.MEDUSA_FF_MEDUSA_V2 == "true"
|
||||||
|
|
||||||
// TODO: this function will be simplified a lot once we drop support for the old api
|
// TODO: this function will be simplified a lot once we drop support for the old api
|
||||||
const { order, fields, limit = 50, expand, offset = 0 } = validated
|
const { order, fields, limit = 50, expand, offset = 0 } = validated
|
||||||
let {
|
let {
|
||||||
@@ -182,7 +184,9 @@ export function prepareListQuery<
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
orderBy["created_at"] = "DESC"
|
if (!isMedusaV2) {
|
||||||
|
orderBy["created_at"] = "DESC"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ export class RemoteQuery {
|
|||||||
"offset",
|
"offset",
|
||||||
"cursor",
|
"cursor",
|
||||||
"sort",
|
"sort",
|
||||||
|
"order",
|
||||||
"withDeleted",
|
"withDeleted",
|
||||||
]
|
]
|
||||||
const availableOptionsAlias = new Map([
|
const availableOptionsAlias = new Map([
|
||||||
|
|||||||
Reference in New Issue
Block a user