fix(modules-sdk): Remote Query "order" as config options (#6925)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"namespaces": [
|
||||
"public"
|
||||
],
|
||||
"namespaces": ["public"],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
@@ -70,6 +68,28 @@
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"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",
|
||||
@@ -77,9 +97,7 @@
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "currency_pkey",
|
||||
"columnNames": [
|
||||
"code"
|
||||
],
|
||||
"columnNames": ["code"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
|
||||
@@ -2,24 +2,27 @@ import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class InitialSetup20240228133303 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
const currencyTables = await this.execute(
|
||||
"select * from information_schema.tables where table_name = 'currency' and table_schema = 'public'"
|
||||
)
|
||||
this.addSql(`
|
||||
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) {
|
||||
// This is so we can still run the api tests, remove completely once that is not needed
|
||||
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;`)
|
||||
}
|
||||
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "created_at" TIMESTAMPTZ NOT NULL DEFAULT now();
|
||||
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "updated_at" TIMESTAMPTZ NULL DEFAULT now();
|
||||
|
||||
this.addSql(`create table if not exists "currency"
|
||||
("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null,
|
||||
"decimal_digits" int not null default 0, "rounding" numeric not null default 0, "raw_rounding" jsonb not null,
|
||||
constraint "currency_pkey" primary key ("code"));`)
|
||||
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "decimal_digits" int not null default 0;
|
||||
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "rounding" numeric not null default 0;
|
||||
ALTER TABLE "currency" ADD COLUMN IF NOT EXISTS "raw_rounding" jsonb;
|
||||
`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,21 @@ class Currency {
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
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
|
||||
|
||||
@@ -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 { 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>(
|
||||
obj: TModel | TModel[],
|
||||
@@ -24,6 +24,8 @@ export function prepareListQuery<
|
||||
T extends RequestQueryFields,
|
||||
TEntity extends BaseEntity
|
||||
>(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
|
||||
const { order, fields, limit = 50, expand, offset = 0 } = validated
|
||||
let {
|
||||
@@ -182,7 +184,9 @@ export function prepareListQuery<
|
||||
)
|
||||
}
|
||||
} else {
|
||||
orderBy["created_at"] = "DESC"
|
||||
if (!isMedusaV2) {
|
||||
orderBy["created_at"] = "DESC"
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -181,6 +181,7 @@ export class RemoteQuery {
|
||||
"offset",
|
||||
"cursor",
|
||||
"sort",
|
||||
"order",
|
||||
"withDeleted",
|
||||
]
|
||||
const availableOptionsAlias = new Map([
|
||||
|
||||
Reference in New Issue
Block a user