Feat(order): order changes (#6435)
What: - Order DB schema migration - BigNumberField Decorator 
This commit is contained in:
1 parent
137cc0ebf8
commit
56b0b45304
33 files changed
+3848
-257
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/types": patch
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
BigNumberField decorator
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,460 @@
|
|||||||
|
import { generatePostgresAlterColummnIfExistStatement } from "@medusajs/utils"
|
||||||
|
import { Migration } from "@mikro-orm/migrations"
|
||||||
|
|
||||||
|
export class Migration20240219102530 extends Migration {
|
||||||
|
async up(): Promise<void> {
|
||||||
|
const sql = `
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_address" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"customer_id" TEXT NULL,
|
||||||
|
"company" TEXT NULL,
|
||||||
|
"first_name" TEXT NULL,
|
||||||
|
"last_name" TEXT NULL,
|
||||||
|
"address_1" TEXT NULL,
|
||||||
|
"address_2" TEXT NULL,
|
||||||
|
"city" TEXT NULL,
|
||||||
|
"country_code" TEXT NULL,
|
||||||
|
"province" TEXT NULL,
|
||||||
|
"postal_code" TEXT NULL,
|
||||||
|
"phone" TEXT NULL,
|
||||||
|
"metadata" JSONB NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_address_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_address_customer_id" ON "order_address" (
|
||||||
|
customer_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"region_id" TEXT NULL,
|
||||||
|
"customer_id" TEXT NULL,
|
||||||
|
"original_order_id" TEXT NULL,
|
||||||
|
"version" INTEGER NOT NULL DEFAULT 1,
|
||||||
|
"sales_channel_id" TEXT NULL,
|
||||||
|
"status" text check (
|
||||||
|
"status" IN (
|
||||||
|
'pending',
|
||||||
|
'completed',
|
||||||
|
'draft',
|
||||||
|
'archived',
|
||||||
|
'canceled',
|
||||||
|
'requires_action'
|
||||||
|
)
|
||||||
|
) NOT NULL DEFAULT 'pending',
|
||||||
|
"email" text NULL,
|
||||||
|
"currency_code" text NOT NULL,
|
||||||
|
"shipping_address_id" text NULL,
|
||||||
|
"billing_address_id" text NULL,
|
||||||
|
"no_notification" boolean NULL,
|
||||||
|
"summary" jsonb NOT NULL,
|
||||||
|
"metadata" jsonb NULL,
|
||||||
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
"deleted_at" timestamptz NULL,
|
||||||
|
"canceled_at" timestamptz NULL,
|
||||||
|
CONSTRAINT "order_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE "order"
|
||||||
|
ADD COLUMN if NOT exists "deleted_at" timestamptz NULL;
|
||||||
|
|
||||||
|
ALTER TABLE "order"
|
||||||
|
ADD COLUMN if NOT exists "original_order_id" text NULL;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_6ff7e874f01b478c115fdd462eb" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_19b0c6293443d1b464f604c3316" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_717a141f96b76d794d409f38129" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_727b872f86c7378474a8fa46147" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_5568d3b9ce9f7abeeb37511ecf2" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_c99a206eb11ad45f6b7f04f2dcc" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_cd7812c96209c5bdd48a6b858b0" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "FK_e1fcce2b18dbcdbe0a5ba9a68b8" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "REL_c99a206eb11ad45f6b7f04f2dc" CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE "order" DROP constraint if EXISTS "UQ_727b872f86c7378474a8fa46147" CASCADE;
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_19b0c6293443d1b464f604c331";
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_579e01fb94f4f58db480857e05";
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_5568d3b9ce9f7abeeb37511ecf";
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_c99a206eb11ad45f6b7f04f2dc";
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_cd7812c96209c5bdd48a6b858b";
|
||||||
|
|
||||||
|
DROP INDEX if exists "IDX_e1fcce2b18dbcdbe0a5ba9a68b";
|
||||||
|
|
||||||
|
${generatePostgresAlterColummnIfExistStatement(
|
||||||
|
"order",
|
||||||
|
["fulfillment_status", "payment_status", "display_id"],
|
||||||
|
"DROP NOT NULL"
|
||||||
|
)}
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_region_id" ON "order" (
|
||||||
|
region_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_customer_id" ON "order" (
|
||||||
|
customer_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_original_order_id" ON "order" (
|
||||||
|
original_order_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_customer_id" ON "order" (
|
||||||
|
customer_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_currency_code" ON "order" (
|
||||||
|
currency_code
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_shipping_address_id" ON "order" (
|
||||||
|
shipping_address_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_billing_address_id" ON "order" (
|
||||||
|
billing_address_id
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_deleted_at" ON "order" (
|
||||||
|
deleted_at
|
||||||
|
)
|
||||||
|
WHERE deleted_at IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_change" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order_id" TEXT NOT NULL,
|
||||||
|
"description" TEXT NULL,
|
||||||
|
"status" text check (
|
||||||
|
"status" IN (
|
||||||
|
'confirmed',
|
||||||
|
'declined',
|
||||||
|
'requested',
|
||||||
|
'pending',
|
||||||
|
'canceled'
|
||||||
|
)
|
||||||
|
) NOT NULL DEFAULT 'pending',
|
||||||
|
"internal_note" text NULL,
|
||||||
|
"created_by" text NOT NULL,
|
||||||
|
"requested_by" text NULL,
|
||||||
|
"requested_at" timestamptz NULL,
|
||||||
|
"confirmed_by" text NULL,
|
||||||
|
"confirmed_at" timestamptz NULL,
|
||||||
|
"declined_by" text NULL,
|
||||||
|
"declined_reason" text NULL,
|
||||||
|
"metadata" jsonb NULL,
|
||||||
|
"declined_at" timestamptz NULL,
|
||||||
|
"canceled_by" text NULL,
|
||||||
|
"canceled_at" timestamptz NULL,
|
||||||
|
"created_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
||||||
|
CONSTRAINT "order_change_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_change_order_id" ON "order_change" (
|
||||||
|
order_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_change_status" ON "order_change" (status);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_change_action" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order_change_id" TEXT NOT NULL,
|
||||||
|
"reference" TEXT NOT NULL,
|
||||||
|
"reference_id" TEXT NOT NULL,
|
||||||
|
"action" JSONB NOT NULL,
|
||||||
|
"metadata" JSONB NULL,
|
||||||
|
"internal_note" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_change_action_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_change_action_order_change_id" ON "order_change_action" (
|
||||||
|
order_change_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_change_action_reference_id" ON "order_change_action" (
|
||||||
|
reference_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_detail" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order_id" TEXT NOT NULL,
|
||||||
|
"version" INTEGER NOT NULL,
|
||||||
|
"item_id" TEXT NOT NULL,
|
||||||
|
"quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_quantity" JSONB NOT NULL,
|
||||||
|
"fulfilled_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_fulfilled_quantity" JSONB NOT NULL,
|
||||||
|
"shipped_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_shipped_quantity" JSONB NOT NULL,
|
||||||
|
"return_requested_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_return_requested_quantity" JSONB NOT NULL,
|
||||||
|
"return_received_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_return_received_quantity" JSONB NOT NULL,
|
||||||
|
"return_dismissed_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_return_dismissed_quantity" JSONB NOT NULL,
|
||||||
|
"written_off_quantity" NUMERIC NOT NULL,
|
||||||
|
"raw_written_off_quantity" JSONB NOT NULL,
|
||||||
|
"summary" JSONB NOT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_detail_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "IDX_order_detail_order_id_item_id_version" ON "order_detail" (
|
||||||
|
order_id,
|
||||||
|
item_id,
|
||||||
|
version
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_line_item" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"totals_id" TEXT NULL,
|
||||||
|
"title" TEXT NOT NULL,
|
||||||
|
"subtitle" TEXT NULL,
|
||||||
|
"thumbnail" TEXT NULL,
|
||||||
|
"variant_id" TEXT NULL,
|
||||||
|
"product_id" TEXT NULL,
|
||||||
|
"product_title" TEXT NULL,
|
||||||
|
"product_description" TEXT NULL,
|
||||||
|
"product_subtitle" TEXT NULL,
|
||||||
|
"product_type" TEXT NULL,
|
||||||
|
"product_collection" TEXT NULL,
|
||||||
|
"product_handle" TEXT NULL,
|
||||||
|
"variant_sku" TEXT NULL,
|
||||||
|
"variant_barcode" TEXT NULL,
|
||||||
|
"variant_title" TEXT NULL,
|
||||||
|
"variant_option_values" JSONB NULL,
|
||||||
|
"requires_shipping" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"is_discountable" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"is_tax_inclusive" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"compare_at_unit_price" NUMERIC NULL,
|
||||||
|
"raw_compare_at_unit_price" JSONB NULL,
|
||||||
|
"unit_price" NUMERIC NOT NULL,
|
||||||
|
"raw_unit_price" JSONB NOT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_line_item_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_line_item_variant_id" ON "order_line_item" (
|
||||||
|
variant_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_line_item_product_id" ON "order_line_item" (
|
||||||
|
product_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_line_item_tax_line" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"description" TEXT NULL,
|
||||||
|
"tax_rate_id" TEXT NULL,
|
||||||
|
"code" TEXT NOT NULL,
|
||||||
|
"rate" NUMERIC NOT NULL,
|
||||||
|
"raw_rate" JSONB NOT NULL,
|
||||||
|
"provider_id" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"item_id" TEXT NULL,
|
||||||
|
CONSTRAINT "order_line_item_tax_line_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_line_item_tax_line_item_id" ON "order_line_item_tax_line" (item_id);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_line_item_adjustment" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"description" TEXT NULL,
|
||||||
|
"promotion_id" TEXT NULL,
|
||||||
|
"code" TEXT NULL,
|
||||||
|
"amount" NUMERIC NOT NULL,
|
||||||
|
"raw_amount" JSONB NOT NULL,
|
||||||
|
"provider_id" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"item_id" TEXT NULL,
|
||||||
|
CONSTRAINT "order_line_item_adjustment_pkey" PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT order_line_item_adjustment_check CHECK (amount >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_line_item_adjustment_item_id" ON "order_line_item_adjustment" (item_id);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_shipping_method" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order_id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"description" JSONB NULL,
|
||||||
|
"amount" NUMERIC NOT NULL,
|
||||||
|
"raw_amount" JSONB NOT NULL,
|
||||||
|
"is_tax_inclusive" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"shipping_option_id" TEXT NULL,
|
||||||
|
"data" JSONB NULL,
|
||||||
|
"metadata" JSONB NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_shipping_method_pkey" PRIMARY KEY ("id"),
|
||||||
|
CONSTRAINT order_shipping_method_check CHECK (amount >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_order_id" ON "order_shipping_method" (
|
||||||
|
order_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_shipping_option_id" ON "order_shipping_method" (
|
||||||
|
shipping_option_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_shipping_method_adjustment" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"description" TEXT NULL,
|
||||||
|
"promotion_id" TEXT NULL,
|
||||||
|
"code" TEXT NULL,
|
||||||
|
"amount" NUMERIC NOT NULL,
|
||||||
|
"raw_amount" JSONB NOT NULL,
|
||||||
|
"provider_id" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"shipping_method_id" TEXT NULL,
|
||||||
|
CONSTRAINT "order_shipping_method_adjustment_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_adjustment_shipping_method_id" ON "order_shipping_method_adjustment" (
|
||||||
|
shipping_method_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_shipping_method_tax_line" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"description" TEXT NULL,
|
||||||
|
"tax_rate_id" TEXT NULL,
|
||||||
|
"code" TEXT NOT NULL,
|
||||||
|
"rate" NUMERIC NOT NULL,
|
||||||
|
"raw_rate" JSONB NOT NULL,
|
||||||
|
"provider_id" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"shipping_method_id" TEXT NULL,
|
||||||
|
CONSTRAINT "order_shipping_method_tax_line_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_shipping_method_tax_line_shipping_method_id" ON "order_shipping_method_tax_line" (
|
||||||
|
shipping_method_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "order_transaction" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"order_id" TEXT NOT NULL,
|
||||||
|
"amount" NUMERIC NOT NULL,
|
||||||
|
"raw_amount" JSONB NOT NULL,
|
||||||
|
"currency_code" TEXT NOT NULL,
|
||||||
|
"reference" TEXT NULL,
|
||||||
|
"reference_id" TEXT NULL,
|
||||||
|
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
|
||||||
|
CONSTRAINT "order_transaction_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_transaction_order_id" ON "order_transaction" (
|
||||||
|
order_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_transaction_currency_code" ON "order_transaction" (
|
||||||
|
currency_code
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "IDX_order_transaction_reference_id" ON "order_transaction" (
|
||||||
|
reference_id
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order"
|
||||||
|
ADD CONSTRAINT "order_shipping_address_id_foreign" FOREIGN KEY ("shipping_address_id") REFERENCES "order_address" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE
|
||||||
|
SET NULL;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order"
|
||||||
|
ADD CONSTRAINT "order_billing_address_id_foreign" FOREIGN KEY ("billing_address_id") REFERENCES "order_address" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE
|
||||||
|
SET NULL;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_change"
|
||||||
|
ADD CONSTRAINT "order_change_order_id_foreign" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_change_action"
|
||||||
|
ADD CONSTRAINT "order_change_action_order_change_id_foreign" FOREIGN KEY ("order_change_id") REFERENCES "order_change" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_detail"
|
||||||
|
ADD CONSTRAINT "order_detail_order_id_foreign" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_detail"
|
||||||
|
ADD CONSTRAINT "order_detail_item_id_foreign" FOREIGN KEY ("item_id") REFERENCES "order_line_item" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_line_item"
|
||||||
|
ADD CONSTRAINT "order_line_item_totals_id_foreign" FOREIGN KEY ("totals_id") REFERENCES "order_detail" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_line_item_tax_line"
|
||||||
|
ADD CONSTRAINT "order_line_item_tax_line_item_id_foreign" FOREIGN KEY ("item_id") REFERENCES "order_line_item" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_line_item_adjustment"
|
||||||
|
ADD CONSTRAINT "order_line_item_adjustment_item_id_foreign" FOREIGN KEY ("item_id") REFERENCES "order_line_item" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_shipping_method"
|
||||||
|
ADD CONSTRAINT "order_shipping_method_order_id_foreign" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_shipping_method_adjustment"
|
||||||
|
ADD CONSTRAINT "order_shipping_method_adjustment_shipping_method_id_foreign" FOREIGN KEY ("shipping_method_id") REFERENCES "order_shipping_method" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_shipping_method_tax_line"
|
||||||
|
ADD CONSTRAINT "order_shipping_method_tax_line_shipping_method_id_foreign" FOREIGN KEY ("shipping_method_id") REFERENCES "order_shipping_method" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE if exists "order_transaction"
|
||||||
|
ADD CONSTRAINT "order_transaction_order_id_foreign" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON
|
||||||
|
UPDATE CASCADE ON
|
||||||
|
DELETE CASCADE;
|
||||||
|
`
|
||||||
|
|
||||||
|
this.addSql(sql)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
|
|
||||||
type OptionalAddressProps = DAL.EntityDateColumns
|
type OptionalAddressProps = DAL.EntityDateColumns
|
||||||
|
|
||||||
const customerIdIndex = createPsqlIndexStatementHelper({
|
const CustomerIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order_address",
|
tableName: "order_address",
|
||||||
columns: "customer_id",
|
columns: "customer_id",
|
||||||
})
|
})
|
||||||
@@ -27,7 +27,7 @@ export default class Address {
|
|||||||
id!: string
|
id!: string
|
||||||
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
@customerIdIndex.MikroORMIndex()
|
@CustomerIdIndex.MikroORMIndex()
|
||||||
customer_id: string | null = null
|
customer_id: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||||
import { BigNumber } from "@medusajs/utils"
|
import { BigNumber, BigNumberField } from "@medusajs/utils"
|
||||||
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
|
import { OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"
|
||||||
|
|
||||||
type OptionalAdjustmentLineProps = DAL.EntityDateColumns
|
type OptionalAdjustmentLineProps = DAL.EntityDateColumns
|
||||||
@@ -27,6 +27,7 @@ export default abstract class AdjustmentLine {
|
|||||||
code: string | null = null
|
code: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "numeric" })
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
amount: BigNumber | number
|
amount: BigNumber | number
|
||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
@Property({ columnType: "jsonb" })
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ export { default as LineItem } from "./line-item"
|
|||||||
export { default as LineItemAdjustment } from "./line-item-adjustment"
|
export { default as LineItemAdjustment } from "./line-item-adjustment"
|
||||||
export { default as LineItemTaxLine } from "./line-item-tax-line"
|
export { default as LineItemTaxLine } from "./line-item-tax-line"
|
||||||
export { default as Order } from "./order"
|
export { default as Order } from "./order"
|
||||||
|
export { default as OrderChange } from "./order-change"
|
||||||
|
export { default as OrderChangeAction } from "./order-change-action"
|
||||||
|
export { default as OrderDetail } from "./order-detail"
|
||||||
export { default as ShippingMethod } from "./shipping-method"
|
export { default as ShippingMethod } from "./shipping-method"
|
||||||
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
|
export { default as ShippingMethodAdjustment } from "./shipping-method-adjustment"
|
||||||
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
|
export { default as ShippingMethodTaxLine } from "./shipping-method-tax-line"
|
||||||
|
export { default as Transaction } from "./transaction"
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
import { generateEntityId } from "@medusajs/utils"
|
import {
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Cascade,
|
Cascade,
|
||||||
@@ -11,6 +14,11 @@ import {
|
|||||||
import AdjustmentLine from "./adjustment-line"
|
import AdjustmentLine from "./adjustment-line"
|
||||||
import LineItem from "./line-item"
|
import LineItem from "./line-item"
|
||||||
|
|
||||||
|
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_line_item_adjustment",
|
||||||
|
columns: "item_id",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order_line_item_adjustment" })
|
@Entity({ tableName: "order_line_item_adjustment" })
|
||||||
@Check<LineItemAdjustment>({
|
@Check<LineItemAdjustment>({
|
||||||
expression: (columns) => `${columns.amount} >= 0`,
|
expression: (columns) => `${columns.amount} >= 0`,
|
||||||
@@ -18,12 +26,12 @@ import LineItem from "./line-item"
|
|||||||
export default class LineItemAdjustment extends AdjustmentLine {
|
export default class LineItemAdjustment extends AdjustmentLine {
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => LineItem,
|
entity: () => LineItem,
|
||||||
index: "IDX_order_line_item_adjustment_item_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
item: LineItem
|
item: LineItem
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
|
@ItemIdIndex.MikroORMIndex()
|
||||||
item_id: string
|
item_id: string
|
||||||
|
|
||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { generateEntityId } from "@medusajs/utils"
|
import {
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Cascade,
|
Cascade,
|
||||||
@@ -10,16 +13,21 @@ import {
|
|||||||
import LineItem from "./line-item"
|
import LineItem from "./line-item"
|
||||||
import TaxLine from "./tax-line"
|
import TaxLine from "./tax-line"
|
||||||
|
|
||||||
|
const ItemIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_line_item_tax_line",
|
||||||
|
columns: "item_id",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order_line_item_tax_line" })
|
@Entity({ tableName: "order_line_item_tax_line" })
|
||||||
export default class LineItemTaxLine extends TaxLine {
|
export default class LineItemTaxLine extends TaxLine {
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => LineItem,
|
entity: () => LineItem,
|
||||||
index: "IDX_order_line_item_tax_line_item_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
item: LineItem
|
item: LineItem
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
|
@ItemIdIndex.MikroORMIndex()
|
||||||
item_id: string
|
item_id: string
|
||||||
|
|
||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
BigNumber,
|
BigNumber,
|
||||||
|
BigNumberField,
|
||||||
createPsqlIndexStatementHelper,
|
createPsqlIndexStatementHelper,
|
||||||
generateEntityId,
|
generateEntityId,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
BeforeUpdate,
|
|
||||||
Cascade,
|
Cascade,
|
||||||
Collection,
|
Collection,
|
||||||
Entity,
|
Entity,
|
||||||
@@ -19,22 +19,21 @@ import {
|
|||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
import LineItemAdjustment from "./line-item-adjustment"
|
import LineItemAdjustment from "./line-item-adjustment"
|
||||||
import LineItemTaxLine from "./line-item-tax-line"
|
import LineItemTaxLine from "./line-item-tax-line"
|
||||||
import Order from "./order"
|
import OrderDetail from "./order-detail"
|
||||||
|
|
||||||
type OptionalLineItemProps =
|
type OptionalLineItemProps =
|
||||||
| "is_discoutable"
|
| "is_discoutable"
|
||||||
| "is_tax_inclusive"
|
| "is_tax_inclusive"
|
||||||
| "compare_at_unit_price"
|
| "compare_at_unit_price"
|
||||||
| "requires_shipping"
|
| "requires_shipping"
|
||||||
| "order"
|
|
||||||
| DAL.EntityDateColumns
|
| DAL.EntityDateColumns
|
||||||
|
|
||||||
const productIdIndex = createPsqlIndexStatementHelper({
|
const ProductIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order_line_item",
|
tableName: "order_line_item",
|
||||||
columns: "product_id",
|
columns: "product_id",
|
||||||
})
|
})
|
||||||
|
|
||||||
const variantIdIndex = createPsqlIndexStatementHelper({
|
const VariantIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order_line_item",
|
tableName: "order_line_item",
|
||||||
columns: "variant_id",
|
columns: "variant_id",
|
||||||
})
|
})
|
||||||
@@ -46,16 +45,12 @@ export default class LineItem {
|
|||||||
@PrimaryKey({ columnType: "text" })
|
@PrimaryKey({ columnType: "text" })
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
|
||||||
order_id: string
|
|
||||||
|
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => Order,
|
entity: () => OrderDetail,
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
index: "IDX_order_line_item_order_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
order: Order
|
totals: OrderDetail
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
title: string
|
title: string
|
||||||
@@ -66,24 +61,18 @@ export default class LineItem {
|
|||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
thumbnail: string | null = null
|
thumbnail: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "numeric" })
|
|
||||||
quantity: BigNumber | number
|
|
||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
|
||||||
raw_quantity: BigNumberRawValue
|
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@variantIdIndex.MikroORMIndex()
|
@VariantIdIndex.MikroORMIndex()
|
||||||
variant_id: string | null = null
|
variant_id: string | null = null
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@productIdIndex.MikroORMIndex()
|
@ProductIdIndex.MikroORMIndex()
|
||||||
product_id: string | null = null
|
product_id: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
@@ -126,12 +115,14 @@ export default class LineItem {
|
|||||||
is_tax_inclusive = false
|
is_tax_inclusive = false
|
||||||
|
|
||||||
@Property({ columnType: "numeric", nullable: true })
|
@Property({ columnType: "numeric", nullable: true })
|
||||||
|
@BigNumberField({ nullable: true })
|
||||||
compare_at_unit_price?: BigNumber | number | null = null
|
compare_at_unit_price?: BigNumber | number | null = null
|
||||||
|
|
||||||
@Property({ columnType: "jsonb", nullable: true })
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
raw_compare_at_unit_price: BigNumberRawValue | null = null
|
raw_compare_at_unit_price: BigNumberRawValue | null = null
|
||||||
|
|
||||||
@Property({ columnType: "numeric" })
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
unit_price: BigNumber | number
|
unit_price: BigNumber | number
|
||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
@Property({ columnType: "jsonb" })
|
||||||
@@ -165,28 +156,10 @@ export default class LineItem {
|
|||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
onCreate() {
|
onCreate() {
|
||||||
this.id = generateEntityId(this.id, "ordli")
|
this.id = generateEntityId(this.id, "ordli")
|
||||||
|
|
||||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
|
||||||
|
|
||||||
this.unit_price = val.numeric
|
|
||||||
this.raw_unit_price = val.raw!
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeUpdate()
|
|
||||||
onUpdate() {
|
|
||||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
|
||||||
|
|
||||||
this.unit_price = val.numeric
|
|
||||||
this.raw_unit_price = val.raw as BigNumberRawValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnInit()
|
@OnInit()
|
||||||
onInit() {
|
onInit() {
|
||||||
this.id = generateEntityId(this.id, "ordli")
|
this.id = generateEntityId(this.id, "ordli")
|
||||||
|
|
||||||
const val = new BigNumber(this.raw_unit_price ?? this.unit_price)
|
|
||||||
|
|
||||||
this.unit_price = val.numeric
|
|
||||||
this.raw_unit_price = val.raw!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import { DAL } from "@medusajs/types"
|
||||||
|
import {
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {
|
||||||
|
BeforeCreate,
|
||||||
|
Cascade,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
OnInit,
|
||||||
|
OptionalProps,
|
||||||
|
PrimaryKey,
|
||||||
|
Property,
|
||||||
|
} from "@mikro-orm/core"
|
||||||
|
import OrderChange from "./order-change"
|
||||||
|
|
||||||
|
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||||
|
|
||||||
|
const OrderChangeIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_change_action",
|
||||||
|
columns: "order_change_id",
|
||||||
|
})
|
||||||
|
|
||||||
|
const ReferenceIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_change_action",
|
||||||
|
columns: "reference_id",
|
||||||
|
})
|
||||||
|
|
||||||
|
@Entity({ tableName: "order_change_action" })
|
||||||
|
export default class OrderChangeAction {
|
||||||
|
[OptionalProps]?: OptionalLineItemProps
|
||||||
|
|
||||||
|
@PrimaryKey({ columnType: "text" })
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
@OrderChangeIdIndex.MikroORMIndex()
|
||||||
|
order_change_id: string
|
||||||
|
|
||||||
|
@ManyToOne({
|
||||||
|
entity: () => OrderChange,
|
||||||
|
fieldName: "order_change_id",
|
||||||
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
|
})
|
||||||
|
order_change: OrderChange
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
reference: string
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
@ReferenceIdIndex.MikroORMIndex()
|
||||||
|
reference_id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
action: Record<string, unknown> = {}
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
|
metadata: Record<string, unknown> | null = null
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "text",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
internal_note: string | null = null
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
@BeforeCreate()
|
||||||
|
onCreate() {
|
||||||
|
this.id = generateEntityId(this.id, "ordchact")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnInit()
|
||||||
|
onInit() {
|
||||||
|
this.id = generateEntityId(this.id, "ordchact")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import { DAL } from "@medusajs/types"
|
||||||
|
import {
|
||||||
|
OrderChangeStatus,
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {
|
||||||
|
BeforeCreate,
|
||||||
|
Cascade,
|
||||||
|
Collection,
|
||||||
|
Entity,
|
||||||
|
Enum,
|
||||||
|
ManyToOne,
|
||||||
|
OnInit,
|
||||||
|
OptionalProps,
|
||||||
|
PrimaryKey,
|
||||||
|
Property,
|
||||||
|
} from "@mikro-orm/core"
|
||||||
|
import { OneToMany } from "typeorm"
|
||||||
|
import Order from "./order"
|
||||||
|
import OrderChangeAction from "./order-change-action"
|
||||||
|
|
||||||
|
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||||
|
|
||||||
|
const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_change",
|
||||||
|
columns: "order_id",
|
||||||
|
})
|
||||||
|
|
||||||
|
const OrderChangeStatusIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_change",
|
||||||
|
columns: "status",
|
||||||
|
})
|
||||||
|
|
||||||
|
@Entity({ tableName: "order_change" })
|
||||||
|
export default class OrderChange {
|
||||||
|
[OptionalProps]?: OptionalLineItemProps
|
||||||
|
|
||||||
|
@PrimaryKey({ columnType: "text" })
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
@OrderIdIndex.MikroORMIndex()
|
||||||
|
order_id: string
|
||||||
|
|
||||||
|
@ManyToOne({
|
||||||
|
entity: () => Order,
|
||||||
|
fieldName: "order_id",
|
||||||
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
|
})
|
||||||
|
order: Order
|
||||||
|
|
||||||
|
@OneToMany(() => OrderChangeAction, (action) => action.order_change_id, {
|
||||||
|
cascade: [Cascade.REMOVE],
|
||||||
|
})
|
||||||
|
actions = new Collection<OrderChangeAction>(this)
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "text",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
description: string | null = null
|
||||||
|
|
||||||
|
@Enum({ items: () => OrderChangeStatus, default: OrderChangeStatus.PENDING })
|
||||||
|
@OrderChangeStatusIndex.MikroORMIndex()
|
||||||
|
status: OrderChangeStatus
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
internal_note: string | null = null
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
created_by: string // customer, user, third party, etc.
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
requested_by: string | null = null // customer or user ID
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "timestamptz",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
requested_at?: Date
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
confirmed_by: string | null = null // customer or user ID
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "timestamptz",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
confirmed_at?: Date
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
declined_by: string | null = null // customer or user ID
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
declined_reason: string | null = null
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
|
metadata: Record<string, unknown> | null = null
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "timestamptz",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
declined_at?: Date
|
||||||
|
|
||||||
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
canceled_by: string | null = null
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "timestamptz",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
canceled_at?: Date
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
@BeforeCreate()
|
||||||
|
onCreate() {
|
||||||
|
this.id = generateEntityId(this.id, "ordch")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnInit()
|
||||||
|
onInit() {
|
||||||
|
this.id = generateEntityId(this.id, "ordch")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||||
|
import {
|
||||||
|
BigNumber,
|
||||||
|
BigNumberField,
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {
|
||||||
|
BeforeCreate,
|
||||||
|
Cascade,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
OnInit,
|
||||||
|
OptionalProps,
|
||||||
|
PrimaryKey,
|
||||||
|
Property,
|
||||||
|
} from "@mikro-orm/core"
|
||||||
|
import { ItemSummary } from "../types/common"
|
||||||
|
import LineItem from "./line-item"
|
||||||
|
import Order from "./order"
|
||||||
|
|
||||||
|
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||||
|
|
||||||
|
const OrderItemVersionIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_detail",
|
||||||
|
columns: ["order_id", "item_id", "version"],
|
||||||
|
unique: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
@Entity({ tableName: "order_detail" })
|
||||||
|
@OrderItemVersionIndex.MikroORMIndex()
|
||||||
|
export default class OrderDetail {
|
||||||
|
[OptionalProps]?: OptionalLineItemProps
|
||||||
|
|
||||||
|
@PrimaryKey({ columnType: "text" })
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
order_id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "integer" })
|
||||||
|
version: number
|
||||||
|
@ManyToOne({
|
||||||
|
entity: () => Order,
|
||||||
|
onDelete: "cascade",
|
||||||
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
|
})
|
||||||
|
order: Order
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
item_id: string
|
||||||
|
|
||||||
|
@ManyToOne({
|
||||||
|
entity: () => LineItem,
|
||||||
|
onDelete: "cascade",
|
||||||
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
|
})
|
||||||
|
item: LineItem
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
fulfilled_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_fulfilled_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
shipped_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_shipped_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
return_requested_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_return_requested_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
return_received_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_return_received_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
return_dismissed_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_return_dismissed_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
written_off_quantity: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_written_off_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
summary: ItemSummary | null = {} as ItemSummary
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
@BeforeCreate()
|
||||||
|
onCreate() {
|
||||||
|
this.id = generateEntityId(this.id, "ordlisum")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnInit()
|
||||||
|
onInit() {
|
||||||
|
this.id = generateEntityId(this.id, "ordlisum")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,45 +17,65 @@ import {
|
|||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
Property,
|
Property,
|
||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
|
import { OrderSummary } from "../types/common"
|
||||||
import Address from "./address"
|
import Address from "./address"
|
||||||
import LineItem from "./line-item"
|
import OrderDetail from "./order-detail"
|
||||||
import ShippingMethod from "./shipping-method"
|
import ShippingMethod from "./shipping-method"
|
||||||
|
import Transaction from "./transaction"
|
||||||
|
|
||||||
type OptionalOrderProps =
|
type OptionalOrderProps =
|
||||||
| "shipping_address"
|
| "shipping_address"
|
||||||
| "billing_address"
|
| "billing_address"
|
||||||
| DAL.EntityDateColumns
|
| DAL.EntityDateColumns
|
||||||
|
|
||||||
const regionIdIndex = createPsqlIndexStatementHelper({
|
const RegionIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order",
|
tableName: "order",
|
||||||
columns: "region_id",
|
columns: "region_id",
|
||||||
where: "deleted_at IS NOT NULL",
|
where: "deleted_at IS NOT NULL",
|
||||||
})
|
})
|
||||||
|
|
||||||
const customerIdIndex = createPsqlIndexStatementHelper({
|
const CustomerIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order",
|
tableName: "order",
|
||||||
columns: "customer_id",
|
columns: "customer_id",
|
||||||
where: "deleted_at IS NOT NULL",
|
where: "deleted_at IS NOT NULL",
|
||||||
})
|
})
|
||||||
|
|
||||||
const salesChannelIdIndex = createPsqlIndexStatementHelper({
|
const SalesChannelIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order",
|
tableName: "order",
|
||||||
columns: "customer_id",
|
columns: "customer_id",
|
||||||
where: "deleted_at IS NOT NULL",
|
where: "deleted_at IS NOT NULL",
|
||||||
})
|
})
|
||||||
|
|
||||||
const orderDeletedAtIndex = createPsqlIndexStatementHelper({
|
const OrderDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order",
|
tableName: "order",
|
||||||
columns: "deleted_at",
|
columns: "deleted_at",
|
||||||
where: "deleted_at IS NOT NULL",
|
where: "deleted_at IS NOT NULL",
|
||||||
})
|
})
|
||||||
|
|
||||||
const currencyCodeIndex = createPsqlIndexStatementHelper({
|
const OriginalOrderIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order",
|
||||||
|
columns: "original_order_id",
|
||||||
|
where: "deleted_at IS NOT NULL",
|
||||||
|
})
|
||||||
|
|
||||||
|
const CurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order",
|
tableName: "order",
|
||||||
columns: "currency_code",
|
columns: "currency_code",
|
||||||
where: "deleted_at IS NOT NULL",
|
where: "deleted_at IS NOT NULL",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const ShippingAddressIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order",
|
||||||
|
columns: "shipping_address_id",
|
||||||
|
where: "deleted_at IS NOT NULL",
|
||||||
|
})
|
||||||
|
|
||||||
|
const BillingAddressIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order",
|
||||||
|
columns: "billing_address_id",
|
||||||
|
where: "deleted_at IS NOT NULL",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order" })
|
@Entity({ tableName: "order" })
|
||||||
export default class Order {
|
export default class Order {
|
||||||
[OptionalProps]?: OptionalOrderProps
|
[OptionalProps]?: OptionalOrderProps
|
||||||
@@ -67,21 +87,34 @@ export default class Order {
|
|||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@regionIdIndex.MikroORMIndex()
|
@RegionIdIndex.MikroORMIndex()
|
||||||
region_id: string | null = null
|
region_id: string | null = null
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@customerIdIndex.MikroORMIndex()
|
@CustomerIdIndex.MikroORMIndex()
|
||||||
customer_id: string | null = null
|
customer_id: string | null = null
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@salesChannelIdIndex.MikroORMIndex()
|
@OriginalOrderIdIndex.MikroORMIndex()
|
||||||
|
original_order_id: string | null = null
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "integer",
|
||||||
|
defaultRaw: "1",
|
||||||
|
})
|
||||||
|
version: number = 1
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "text",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
@SalesChannelIdIndex.MikroORMIndex()
|
||||||
sales_channel_id: string | null = null
|
sales_channel_id: string | null = null
|
||||||
|
|
||||||
@Enum({ items: () => OrderStatus, default: OrderStatus.PENDING })
|
@Enum({ items: () => OrderStatus, default: OrderStatus.PENDING })
|
||||||
@@ -91,29 +124,29 @@ export default class Order {
|
|||||||
email: string | null = null
|
email: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
@currencyCodeIndex.MikroORMIndex()
|
@CurrencyCodeIndex.MikroORMIndex()
|
||||||
currency_code: string
|
currency_code: string
|
||||||
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
@ShippingAddressIdIndex.MikroORMIndex()
|
||||||
shipping_address_id?: string | null
|
shipping_address_id?: string | null
|
||||||
|
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => Address,
|
entity: () => Address,
|
||||||
fieldName: "shipping_address_id",
|
fieldName: "shipping_address_id",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
index: "IDX_order_shipping_address_id",
|
|
||||||
cascade: [Cascade.PERSIST],
|
cascade: [Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
shipping_address?: Address | null
|
shipping_address?: Address | null
|
||||||
|
|
||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
|
@BillingAddressIdIndex.MikroORMIndex()
|
||||||
billing_address_id?: string | null
|
billing_address_id?: string | null
|
||||||
|
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => Address,
|
entity: () => Address,
|
||||||
fieldName: "billing_address_id",
|
fieldName: "billing_address_id",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
index: "IDX_order_billing_address_id",
|
|
||||||
cascade: [Cascade.PERSIST],
|
cascade: [Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
billing_address?: Address | null
|
billing_address?: Address | null
|
||||||
@@ -121,19 +154,27 @@ export default class Order {
|
|||||||
@Property({ columnType: "boolean", nullable: true })
|
@Property({ columnType: "boolean", nullable: true })
|
||||||
no_notification: boolean | null = null
|
no_notification: boolean | null = null
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
summary: OrderSummary | null = {} as OrderSummary
|
||||||
|
|
||||||
@Property({ columnType: "jsonb", nullable: true })
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
metadata: Record<string, unknown> | null = null
|
metadata: Record<string, unknown> | null = null
|
||||||
|
|
||||||
@OneToMany(() => LineItem, (lineItem) => lineItem.order, {
|
@OneToMany(() => OrderDetail, (itemDetail) => itemDetail.order, {
|
||||||
cascade: [Cascade.REMOVE],
|
cascade: [Cascade.REMOVE],
|
||||||
})
|
})
|
||||||
items = new Collection<LineItem>(this)
|
items = new Collection<OrderDetail>(this)
|
||||||
|
|
||||||
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.order, {
|
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.order, {
|
||||||
cascade: [Cascade.REMOVE],
|
cascade: [Cascade.REMOVE],
|
||||||
})
|
})
|
||||||
shipping_methods = new Collection<ShippingMethod>(this)
|
shipping_methods = new Collection<ShippingMethod>(this)
|
||||||
|
|
||||||
|
@OneToMany(() => Transaction, (transaction) => transaction.order, {
|
||||||
|
cascade: [Cascade.REMOVE],
|
||||||
|
})
|
||||||
|
transactions = new Collection<Transaction>(this)
|
||||||
|
|
||||||
@Property({
|
@Property({
|
||||||
onCreate: () => new Date(),
|
onCreate: () => new Date(),
|
||||||
columnType: "timestamptz",
|
columnType: "timestamptz",
|
||||||
@@ -150,7 +191,7 @@ export default class Order {
|
|||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
|
||||||
@Property({ columnType: "timestamptz", nullable: true })
|
@Property({ columnType: "timestamptz", nullable: true })
|
||||||
@orderDeletedAtIndex.MikroORMIndex()
|
@OrderDeletedAtIndex.MikroORMIndex()
|
||||||
deleted_at: Date | null = null
|
deleted_at: Date | null = null
|
||||||
|
|
||||||
@Property({ columnType: "timestamptz", nullable: true })
|
@Property({ columnType: "timestamptz", nullable: true })
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { generateEntityId } from "@medusajs/utils"
|
import {
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Cascade,
|
Cascade,
|
||||||
@@ -10,17 +13,22 @@ import {
|
|||||||
import AdjustmentLine from "./adjustment-line"
|
import AdjustmentLine from "./adjustment-line"
|
||||||
import ShippingMethod from "./shipping-method"
|
import ShippingMethod from "./shipping-method"
|
||||||
|
|
||||||
|
const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_shipping_method_adjustment",
|
||||||
|
columns: "shipping_method_id",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order_shipping_method_adjustment" })
|
@Entity({ tableName: "order_shipping_method_adjustment" })
|
||||||
export default class ShippingMethodAdjustment extends AdjustmentLine {
|
export default class ShippingMethodAdjustment extends AdjustmentLine {
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => ShippingMethod,
|
entity: () => ShippingMethod,
|
||||||
fieldName: "shipping_method_id",
|
fieldName: "shipping_method_id",
|
||||||
index: "IDX_order_shipping_method_adjustment_shipping_method_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
shipping_method: ShippingMethod
|
shipping_method: ShippingMethod
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
|
@ShippingMethodIdIdIndex.MikroORMIndex()
|
||||||
shipping_method_id: string
|
shipping_method_id: string
|
||||||
|
|
||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { generateEntityId } from "@medusajs/utils"
|
import {
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import {
|
import {
|
||||||
BeforeCreate,
|
BeforeCreate,
|
||||||
Cascade,
|
Cascade,
|
||||||
@@ -10,17 +13,22 @@ import {
|
|||||||
import ShippingMethod from "./shipping-method"
|
import ShippingMethod from "./shipping-method"
|
||||||
import TaxLine from "./tax-line"
|
import TaxLine from "./tax-line"
|
||||||
|
|
||||||
|
const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_shipping_method_tax_line",
|
||||||
|
columns: "shipping_method_id",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order_shipping_method_tax_line" })
|
@Entity({ tableName: "order_shipping_method_tax_line" })
|
||||||
export default class ShippingMethodTaxLine extends TaxLine {
|
export default class ShippingMethodTaxLine extends TaxLine {
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => ShippingMethod,
|
entity: () => ShippingMethod,
|
||||||
fieldName: "shipping_method_id",
|
fieldName: "shipping_method_id",
|
||||||
index: "IDX_order_tax_line_shipping_method_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
shipping_method: ShippingMethod
|
shipping_method: ShippingMethod
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
|
@ShippingMethodIdIdIndex.MikroORMIndex()
|
||||||
shipping_method_id: string
|
shipping_method_id: string
|
||||||
|
|
||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { BigNumberRawValue } from "@medusajs/types"
|
import { BigNumberRawValue } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
BigNumber,
|
BigNumber,
|
||||||
|
BigNumberField,
|
||||||
createPsqlIndexStatementHelper,
|
createPsqlIndexStatementHelper,
|
||||||
generateEntityId,
|
generateEntityId,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
@@ -16,16 +17,20 @@ import {
|
|||||||
PrimaryKey,
|
PrimaryKey,
|
||||||
Property,
|
Property,
|
||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
import { BeforeUpdate } from "typeorm"
|
|
||||||
import Order from "./order"
|
import Order from "./order"
|
||||||
import ShippingMethodAdjustment from "./shipping-method-adjustment"
|
import ShippingMethodAdjustment from "./shipping-method-adjustment"
|
||||||
import ShippingMethodTaxLine from "./shipping-method-tax-line"
|
import ShippingMethodTaxLine from "./shipping-method-tax-line"
|
||||||
|
|
||||||
const shippingOptionIdIndex = createPsqlIndexStatementHelper({
|
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
|
||||||
tableName: "order_shipping_method",
|
tableName: "order_shipping_method",
|
||||||
columns: "shipping_option_id",
|
columns: "shipping_option_id",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_shipping_method",
|
||||||
|
columns: "order_id",
|
||||||
|
})
|
||||||
|
|
||||||
@Entity({ tableName: "order_shipping_method" })
|
@Entity({ tableName: "order_shipping_method" })
|
||||||
@Check<ShippingMethod>({ expression: (columns) => `${columns.amount} >= 0` })
|
@Check<ShippingMethod>({ expression: (columns) => `${columns.amount} >= 0` })
|
||||||
export default class ShippingMethod {
|
export default class ShippingMethod {
|
||||||
@@ -33,12 +38,12 @@ export default class ShippingMethod {
|
|||||||
id: string
|
id: string
|
||||||
|
|
||||||
@Property({ columnType: "text" })
|
@Property({ columnType: "text" })
|
||||||
|
@OrderIdIndex.MikroORMIndex()
|
||||||
order_id: string
|
order_id: string
|
||||||
|
|
||||||
@ManyToOne({
|
@ManyToOne({
|
||||||
entity: () => Order,
|
entity: () => Order,
|
||||||
fieldName: "order_id",
|
fieldName: "order_id",
|
||||||
index: "IDX_order_shipping_method_order_id",
|
|
||||||
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
})
|
})
|
||||||
order: Order
|
order: Order
|
||||||
@@ -50,6 +55,7 @@ export default class ShippingMethod {
|
|||||||
description: string | null = null
|
description: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "numeric" })
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
amount: BigNumber | number
|
amount: BigNumber | number
|
||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
@Property({ columnType: "jsonb" })
|
||||||
@@ -62,7 +68,7 @@ export default class ShippingMethod {
|
|||||||
columnType: "text",
|
columnType: "text",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@shippingOptionIdIndex.MikroORMIndex()
|
@ShippingOptionIdIndex.MikroORMIndex()
|
||||||
shipping_option_id: string | null = null
|
shipping_option_id: string | null = null
|
||||||
|
|
||||||
@Property({ columnType: "jsonb", nullable: true })
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
@@ -107,28 +113,9 @@ export default class ShippingMethod {
|
|||||||
@BeforeCreate()
|
@BeforeCreate()
|
||||||
onCreate() {
|
onCreate() {
|
||||||
this.id = generateEntityId(this.id, "ordsm")
|
this.id = generateEntityId(this.id, "ordsm")
|
||||||
|
|
||||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
|
||||||
|
|
||||||
this.amount = val.numeric
|
|
||||||
this.raw_amount = val.raw!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeUpdate()
|
|
||||||
onUpdate() {
|
|
||||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
|
||||||
|
|
||||||
this.amount = val.numeric
|
|
||||||
this.raw_amount = val.raw as BigNumberRawValue
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnInit()
|
@OnInit()
|
||||||
onInit() {
|
onInit() {
|
||||||
this.id = generateEntityId(this.id, "ordsm")
|
this.id = generateEntityId(this.id, "ordsm")
|
||||||
|
|
||||||
const val = new BigNumber(this.raw_amount ?? this.amount)
|
|
||||||
|
|
||||||
this.amount = val.numeric
|
|
||||||
this.raw_amount = val.raw!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BigNumberRawValue } from "@medusajs/types"
|
import { BigNumberRawValue } from "@medusajs/types"
|
||||||
import { BigNumber } from "@medusajs/utils"
|
import { BigNumber, BigNumberField } from "@medusajs/utils"
|
||||||
import { PrimaryKey, Property } from "@mikro-orm/core"
|
import { PrimaryKey, Property } from "@mikro-orm/core"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +23,7 @@ export default abstract class TaxLine {
|
|||||||
code: string
|
code: string
|
||||||
|
|
||||||
@Property({ columnType: "numeric" })
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
rate: BigNumber | number
|
rate: BigNumber | number
|
||||||
|
|
||||||
@Property({ columnType: "jsonb" })
|
@Property({ columnType: "jsonb" })
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { BigNumberRawValue, DAL } from "@medusajs/types"
|
||||||
|
import {
|
||||||
|
BigNumber,
|
||||||
|
BigNumberField,
|
||||||
|
createPsqlIndexStatementHelper,
|
||||||
|
generateEntityId,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import {
|
||||||
|
BeforeCreate,
|
||||||
|
Cascade,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
OnInit,
|
||||||
|
OptionalProps,
|
||||||
|
PrimaryKey,
|
||||||
|
Property,
|
||||||
|
} from "@mikro-orm/core"
|
||||||
|
import Order from "./order"
|
||||||
|
|
||||||
|
type OptionalLineItemProps = DAL.EntityDateColumns
|
||||||
|
|
||||||
|
const ReferenceIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_transaction",
|
||||||
|
columns: "reference_id",
|
||||||
|
})
|
||||||
|
|
||||||
|
const OrderIdIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_transaction",
|
||||||
|
columns: "order_id",
|
||||||
|
})
|
||||||
|
|
||||||
|
const CurrencyCodeIndex = createPsqlIndexStatementHelper({
|
||||||
|
tableName: "order_transaction",
|
||||||
|
columns: "currency_code",
|
||||||
|
})
|
||||||
|
|
||||||
|
@Entity({ tableName: "order_transaction" })
|
||||||
|
export default class Transaction {
|
||||||
|
[OptionalProps]?: OptionalLineItemProps
|
||||||
|
|
||||||
|
@PrimaryKey({ columnType: "text" })
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
@OrderIdIndex.MikroORMIndex()
|
||||||
|
order_id: string
|
||||||
|
|
||||||
|
@ManyToOne({
|
||||||
|
entity: () => Order,
|
||||||
|
fieldName: "order_id",
|
||||||
|
cascade: [Cascade.REMOVE, Cascade.PERSIST],
|
||||||
|
})
|
||||||
|
order: Order
|
||||||
|
|
||||||
|
@Property({ columnType: "numeric" })
|
||||||
|
@BigNumberField()
|
||||||
|
amount: BigNumber | number
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb" })
|
||||||
|
raw_amount: BigNumberRawValue
|
||||||
|
|
||||||
|
@Property({ columnType: "text" })
|
||||||
|
@CurrencyCodeIndex.MikroORMIndex()
|
||||||
|
currency_code: string
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "text",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
reference: string | null = null
|
||||||
|
|
||||||
|
@Property({
|
||||||
|
columnType: "text",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
@ReferenceIdIndex.MikroORMIndex()
|
||||||
|
reference_id: string | null = null
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
@BeforeCreate()
|
||||||
|
onCreate() {
|
||||||
|
this.id = generateEntityId(this.id, "ordtrx")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnInit()
|
||||||
|
onInit() {
|
||||||
|
this.id = generateEntityId(this.id, "ordtrx")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,9 +23,13 @@ import {
|
|||||||
LineItemAdjustment,
|
LineItemAdjustment,
|
||||||
LineItemTaxLine,
|
LineItemTaxLine,
|
||||||
Order,
|
Order,
|
||||||
|
OrderChange,
|
||||||
|
OrderChangeAction,
|
||||||
|
OrderDetail,
|
||||||
ShippingMethod,
|
ShippingMethod,
|
||||||
ShippingMethodAdjustment,
|
ShippingMethodAdjustment,
|
||||||
ShippingMethodTaxLine,
|
ShippingMethodTaxLine,
|
||||||
|
Transaction,
|
||||||
} from "@models"
|
} from "@models"
|
||||||
import {
|
import {
|
||||||
CreateOrderLineItemDTO,
|
CreateOrderLineItemDTO,
|
||||||
@@ -48,6 +52,10 @@ type InjectedDependencies = {
|
|||||||
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
lineItemTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
shippingMethodTaxLineService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
|
transactionService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
|
orderChangeService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
|
orderChangeActionService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
|
orderDetailService: ModulesSdkTypes.InternalModuleService<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateMethodForModels = [
|
const generateMethodForModels = [
|
||||||
@@ -58,6 +66,10 @@ const generateMethodForModels = [
|
|||||||
ShippingMethod,
|
ShippingMethod,
|
||||||
ShippingMethodAdjustment,
|
ShippingMethodAdjustment,
|
||||||
ShippingMethodTaxLine,
|
ShippingMethodTaxLine,
|
||||||
|
Transaction,
|
||||||
|
OrderChange,
|
||||||
|
OrderChangeAction,
|
||||||
|
OrderDetail,
|
||||||
]
|
]
|
||||||
|
|
||||||
export default class OrderModuleService<
|
export default class OrderModuleService<
|
||||||
@@ -68,7 +80,11 @@ export default class OrderModuleService<
|
|||||||
TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine,
|
TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine,
|
||||||
TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment,
|
TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment,
|
||||||
TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine,
|
TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine,
|
||||||
TShippingMethod extends ShippingMethod = ShippingMethod
|
TShippingMethod extends ShippingMethod = ShippingMethod,
|
||||||
|
TTransaction extends Transaction = Transaction,
|
||||||
|
TOrderChange extends OrderChange = OrderChange,
|
||||||
|
TOrderChangeAction extends OrderChangeAction = OrderChangeAction,
|
||||||
|
TOrderDetail extends OrderDetail = OrderDetail
|
||||||
>
|
>
|
||||||
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
extends ModulesSdkUtils.abstractModuleServiceFactory<
|
||||||
InjectedDependencies,
|
InjectedDependencies,
|
||||||
@@ -83,6 +99,9 @@ export default class OrderModuleService<
|
|||||||
dto: OrderTypes.OrderShippingMethodAdjustmentDTO
|
dto: OrderTypes.OrderShippingMethodAdjustmentDTO
|
||||||
}
|
}
|
||||||
ShippingMethodTaxLine: { dto: OrderTypes.OrderShippingMethodTaxLineDTO }
|
ShippingMethodTaxLine: { dto: OrderTypes.OrderShippingMethodTaxLineDTO }
|
||||||
|
Transaction: { dto: OrderTypes.OrderTransactionDTO }
|
||||||
|
Change: { dto: OrderTypes.OrderChangeDTO }
|
||||||
|
ChangeAction: { dto: OrderTypes.OrderChangeActionDTO }
|
||||||
}
|
}
|
||||||
>(Order, generateMethodForModels, entityNameToLinkableKeysMap)
|
>(Order, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||||
implements IOrderModuleService
|
implements IOrderModuleService
|
||||||
@@ -96,6 +115,10 @@ export default class OrderModuleService<
|
|||||||
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
|
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
|
||||||
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
|
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
|
||||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>
|
protected shippingMethodTaxLineService_: ModulesSdkTypes.InternalModuleService<TShippingMethodTaxLine>
|
||||||
|
protected transactionService_: ModulesSdkTypes.InternalModuleService<TTransaction>
|
||||||
|
protected orderChangeService_: ModulesSdkTypes.InternalModuleService<TOrderChange>
|
||||||
|
protected orderChangeActionService_: ModulesSdkTypes.InternalModuleService<TOrderChangeAction>
|
||||||
|
protected orderDetailService_: ModulesSdkTypes.InternalModuleService<TOrderDetail>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{
|
{
|
||||||
@@ -108,6 +131,10 @@ export default class OrderModuleService<
|
|||||||
lineItemAdjustmentService,
|
lineItemAdjustmentService,
|
||||||
shippingMethodTaxLineService,
|
shippingMethodTaxLineService,
|
||||||
lineItemTaxLineService,
|
lineItemTaxLineService,
|
||||||
|
transactionService,
|
||||||
|
orderChangeService,
|
||||||
|
orderChangeActionService,
|
||||||
|
orderDetailService,
|
||||||
}: InjectedDependencies,
|
}: InjectedDependencies,
|
||||||
protected readonly moduleDeclaration: InternalModuleDeclaration
|
protected readonly moduleDeclaration: InternalModuleDeclaration
|
||||||
) {
|
) {
|
||||||
@@ -123,6 +150,10 @@ export default class OrderModuleService<
|
|||||||
this.lineItemAdjustmentService_ = lineItemAdjustmentService
|
this.lineItemAdjustmentService_ = lineItemAdjustmentService
|
||||||
this.shippingMethodTaxLineService_ = shippingMethodTaxLineService
|
this.shippingMethodTaxLineService_ = shippingMethodTaxLineService
|
||||||
this.lineItemTaxLineService_ = lineItemTaxLineService
|
this.lineItemTaxLineService_ = lineItemTaxLineService
|
||||||
|
this.transactionService_ = transactionService
|
||||||
|
this.orderChangeService_ = orderChangeService
|
||||||
|
this.orderChangeActionService_ = orderChangeActionService
|
||||||
|
this.orderDetailService_ = orderDetailService
|
||||||
}
|
}
|
||||||
|
|
||||||
__joinerConfig(): ModuleJoinerConfig {
|
__joinerConfig(): ModuleJoinerConfig {
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { BigNumberInput } from "@medusajs/types"
|
|
||||||
|
|
||||||
export interface UpdateOrderShippingMethodDTO {
|
|
||||||
id: string
|
|
||||||
name?: string
|
|
||||||
amount?: BigNumberInput
|
|
||||||
data?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,11 @@
|
|||||||
export interface UpsertOrderAddressDTO {
|
import { OrderTypes } from "@medusajs/types"
|
||||||
customer_id?: string
|
|
||||||
company?: string
|
export type UpsertOrderAddressDTO = OrderTypes.UpsertOrderAddressDTO
|
||||||
first_name?: string
|
|
||||||
last_name?: string
|
|
||||||
address_1?: string
|
|
||||||
address_2?: string
|
|
||||||
city?: string
|
|
||||||
country_code?: string
|
|
||||||
province?: string
|
|
||||||
postal_code?: string
|
|
||||||
phone?: string
|
|
||||||
metadata?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateOrderAddressDTO extends UpsertOrderAddressDTO {
|
export interface UpdateOrderAddressDTO extends UpsertOrderAddressDTO {
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateOrderAddressDTO extends UpsertOrderAddressDTO {}
|
export interface CreateOrderAddressDTO extends UpsertOrderAddressDTO {}
|
||||||
|
|
||||||
|
export type OrderAddressDTO = OrderTypes.OrderAddressDTO
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { BigNumber } from "@medusajs/utils"
|
||||||
|
|
||||||
|
export type OrderSummary = {
|
||||||
|
total: BigNumber
|
||||||
|
subtotal: BigNumber
|
||||||
|
total_tax: BigNumber
|
||||||
|
|
||||||
|
ordered_total: BigNumber
|
||||||
|
fulfilled_total: BigNumber
|
||||||
|
returned_total: BigNumber
|
||||||
|
return_request_total: BigNumber
|
||||||
|
write_off_total: BigNumber
|
||||||
|
projected_total: BigNumber
|
||||||
|
|
||||||
|
net_total: BigNumber
|
||||||
|
net_subtotal: BigNumber
|
||||||
|
net_total_tax: BigNumber
|
||||||
|
|
||||||
|
future_total: BigNumber
|
||||||
|
future_subtotal: BigNumber
|
||||||
|
future_total_tax: BigNumber
|
||||||
|
future_projected_total: BigNumber
|
||||||
|
|
||||||
|
balance: BigNumber
|
||||||
|
future_balance: BigNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ItemSummary = {
|
||||||
|
returnable_quantity: BigNumber
|
||||||
|
ordered_quantity: BigNumber
|
||||||
|
fulfilled_quantity: BigNumber
|
||||||
|
return_requested_quantity: BigNumber
|
||||||
|
return_received_quantity: BigNumber
|
||||||
|
return_dismissed_quantity: BigNumber
|
||||||
|
written_off_quantity: BigNumber
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ export * from "./order"
|
|||||||
export * from "./shipping-method"
|
export * from "./shipping-method"
|
||||||
export * from "./shipping-method-adjustment"
|
export * from "./shipping-method-adjustment"
|
||||||
export * from "./shipping-method-tax-line"
|
export * from "./shipping-method-tax-line"
|
||||||
|
export * from "./transaction"
|
||||||
|
|
||||||
export type InitializeModuleInjectableDependencies = {
|
export type InitializeModuleInjectableDependencies = {
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import { BigNumberInput } from "@medusajs/types"
|
import { OrderTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export interface CreateOrderLineItemAdjustmentDTO {
|
export type CreateOrderLineItemAdjustmentDTO =
|
||||||
item_id: string
|
OrderTypes.CreateOrderLineItemAdjustmentDTO
|
||||||
amount: BigNumberInput
|
|
||||||
code?: string
|
|
||||||
description?: string
|
|
||||||
promotion_id?: string
|
|
||||||
provider_id?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateOrderLineItemAdjustmentDTO
|
export interface UpdateOrderLineItemAdjustmentDTO
|
||||||
extends Partial<CreateOrderLineItemAdjustmentDTO> {
|
extends Partial<CreateOrderLineItemAdjustmentDTO> {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface CreateOrderDTO {
|
|||||||
|
|
||||||
export interface UpdateOrderDTO {
|
export interface UpdateOrderDTO {
|
||||||
id: string
|
id: string
|
||||||
|
version?: number
|
||||||
region_id?: string
|
region_id?: string
|
||||||
customer_id?: string
|
customer_id?: string
|
||||||
sales_channel_id?: string
|
sales_channel_id?: string
|
||||||
|
|||||||
@@ -1,19 +1,7 @@
|
|||||||
import { BigNumberInput } from "@medusajs/types"
|
import { OrderTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export interface CreateOrderShippingMethodAdjustmentDTO {
|
export type CreateOrderShippingMethodAdjustmentDTO =
|
||||||
shipping_method_id: string
|
OrderTypes.CreateOrderShippingMethodAdjustmentDTO
|
||||||
code: string
|
|
||||||
amount: BigNumberInput
|
|
||||||
description?: string
|
|
||||||
promotion_id?: string
|
|
||||||
provider_id?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UpdateOrderShippingMethodAdjustmentDTO {
|
export type UpdateOrderShippingMethodAdjustmentDTO =
|
||||||
id: string
|
OrderTypes.UpdateOrderShippingMethodAdjustmentDTO
|
||||||
code?: string
|
|
||||||
amount?: BigNumberInput
|
|
||||||
description?: string
|
|
||||||
promotion_id?: string
|
|
||||||
provider_id?: string
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
import { BigNumberInput } from "@medusajs/types"
|
import { OrderTypes } from "@medusajs/types"
|
||||||
|
|
||||||
export interface UpdateOrderTaxLineDTO {
|
export type CreateOrderTaxLineDTO = OrderTypes.CreateOrderTaxLineDTO
|
||||||
id: string
|
|
||||||
description?: string
|
|
||||||
tax_rate_id?: string
|
|
||||||
code?: string
|
|
||||||
rate?: BigNumberInput
|
|
||||||
provider_id?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CreateOrderTaxLineDTO {
|
export type UpdateOrderTaxLineDTO = OrderTypes.UpdateOrderTaxLineDTO
|
||||||
description?: string
|
|
||||||
tax_rate_id?: string
|
|
||||||
code: string
|
|
||||||
rate: BigNumberInput
|
|
||||||
provider_id?: string
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { OrderTypes } from "@medusajs/types"
|
||||||
|
|
||||||
|
export type OrderTransactionDTO = OrderTypes.OrderTransactionDTO
|
||||||
@@ -1,5 +1,41 @@
|
|||||||
import { BaseFilterable } from "../dal"
|
import { BaseFilterable } from "../dal"
|
||||||
import { OperatorMap } from "../dal/utils"
|
import { OperatorMap } from "../dal/utils"
|
||||||
|
import { BigNumberRawValue } from "../totals"
|
||||||
|
|
||||||
|
type OrderSummary = {
|
||||||
|
total: number
|
||||||
|
subtotal: number
|
||||||
|
total_tax: number
|
||||||
|
|
||||||
|
ordered_total: number
|
||||||
|
fulfilled_total: number
|
||||||
|
returned_total: number
|
||||||
|
return_request_total: number
|
||||||
|
write_off_total: number
|
||||||
|
projected_total: number
|
||||||
|
|
||||||
|
net_total: number
|
||||||
|
net_subtotal: number
|
||||||
|
net_total_tax: number
|
||||||
|
|
||||||
|
future_total: number
|
||||||
|
future_subtotal: number
|
||||||
|
future_total_tax: number
|
||||||
|
future_projected_total: number
|
||||||
|
|
||||||
|
balance: number
|
||||||
|
future_balance: number
|
||||||
|
}
|
||||||
|
|
||||||
|
type ItemSummary = {
|
||||||
|
returnable_quantity: number
|
||||||
|
ordered_quantity: number
|
||||||
|
fulfilled_quantity: number
|
||||||
|
return_requested_quantity: number
|
||||||
|
return_received_quantity: number
|
||||||
|
return_dismissed_quantity: number
|
||||||
|
written_off_quantity: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface OrderAdjustmentLineDTO {
|
export interface OrderAdjustmentLineDTO {
|
||||||
/**
|
/**
|
||||||
@@ -251,10 +287,6 @@ export interface OrderShippingMethodDTO {
|
|||||||
*/
|
*/
|
||||||
updated_at: Date | string
|
updated_at: Date | string
|
||||||
|
|
||||||
original_total: number
|
|
||||||
original_subtotal: number
|
|
||||||
original_tax_total: number
|
|
||||||
|
|
||||||
total: number
|
total: number
|
||||||
subtotal: number
|
subtotal: number
|
||||||
tax_total: number
|
tax_total: number
|
||||||
@@ -280,127 +312,204 @@ export interface OrderLineItemTotalsDTO {
|
|||||||
|
|
||||||
export interface OrderLineItemDTO extends OrderLineItemTotalsDTO {
|
export interface OrderLineItemDTO extends OrderLineItemTotalsDTO {
|
||||||
/**
|
/**
|
||||||
* The ID of the line item.
|
* The ID of the order line item.
|
||||||
*/
|
*/
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The title of the line item.
|
* The title of the order line item.
|
||||||
*/
|
*/
|
||||||
title: string
|
title: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The subtitle of the line item.
|
* The subtitle of the order line item.
|
||||||
*/
|
*/
|
||||||
subtitle?: string
|
subtitle?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url of the line item thumbnail.
|
* The thumbnail of the order line item.
|
||||||
*/
|
*/
|
||||||
thumbnail?: string
|
thumbnail?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The line item quantity
|
* The ID of the variant associated with the order line item.
|
||||||
*/
|
*/
|
||||||
quantity: number
|
variant_id?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product ID of the line item.
|
* The ID of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_id?: string
|
product_id?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product title of the line item.
|
* The title of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_title?: string
|
product_title?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product description of the line item.
|
* The description of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_description?: string
|
product_description?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product subtitle of the line item.
|
* The subtitle of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_subtitle?: string
|
product_subtitle?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product type of the line item.
|
* The type of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_type?: string
|
product_type?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product collection of the line item.
|
* The collection of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_collection?: string
|
product_collection?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The product handle of the line item.
|
* The handle of the product associated with the order line item.
|
||||||
*/
|
*/
|
||||||
product_handle?: string
|
product_handle?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variant ID of the line item.
|
* The SKU (stock keeping unit) of the variant associated with the order line item.
|
||||||
*/
|
*/
|
||||||
variant_id?: string
|
variant_sku?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variant sku of the line item.
|
* The barcode of the variant associated with the order line item.
|
||||||
*/
|
*/
|
||||||
variant_sku?: string
|
variant_barcode?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variant barcode of the line item.
|
* The title of the variant associated with the order line item.
|
||||||
*/
|
*/
|
||||||
variant_barcode?: string
|
variant_title?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variant title of the line item.
|
* The option values of the variant associated with the order line item.
|
||||||
*/
|
*/
|
||||||
variant_title?: string
|
variant_option_values?: Record<string, unknown> | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variant option values of the line item.
|
* Indicates whether the order line item requires shipping.
|
||||||
*/
|
|
||||||
variant_option_values?: Record<string, unknown>
|
|
||||||
/**
|
|
||||||
* Whether the line item requires shipping or not
|
|
||||||
*/
|
*/
|
||||||
requires_shipping: boolean
|
requires_shipping: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the line item is discountable or not
|
* Indicates whether the order line item is discountable.
|
||||||
*/
|
*/
|
||||||
is_discountable: boolean
|
is_discountable: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the line item price is tax inclusive or not
|
* Indicates whether the order line item price is tax inclusive.
|
||||||
*/
|
*/
|
||||||
is_tax_inclusive: boolean
|
is_tax_inclusive: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The original price of the item before an adjustment or a sale.
|
* The compare at unit price of the order line item.
|
||||||
*/
|
*/
|
||||||
compare_at_unit_price?: number
|
compare_at_unit_price?: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The price of the item
|
* The raw compare at unit price of the order line item.
|
||||||
|
*/
|
||||||
|
raw_compare_at_unit_price?: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unit price of the order line item.
|
||||||
*/
|
*/
|
||||||
unit_price: number
|
unit_price: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated tax lines.
|
* The raw unit price of the order line item.
|
||||||
*
|
|
||||||
* @expandable
|
|
||||||
*/
|
*/
|
||||||
tax_lines?: OrderLineItemTaxLineDTO[]
|
raw_unit_price: BigNumberRawValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated adjustments.
|
* The quantity of the order line item.
|
||||||
*
|
|
||||||
* @expandable
|
|
||||||
*/
|
*/
|
||||||
adjustments?: OrderLineItemAdjustmentDTO[]
|
quantity: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated order.
|
* The raw quantity of the order line item.
|
||||||
*
|
|
||||||
* @expandable
|
|
||||||
*/
|
*/
|
||||||
order: OrderDTO
|
raw_quantity: BigNumberRawValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID of the associated order.
|
* The fulfilled quantity of the order line item.
|
||||||
*/
|
*/
|
||||||
order_id: string
|
fulfilled_quantity: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds custom data in key-value pairs.
|
* The raw fulfilled quantity of the order line item.
|
||||||
*/
|
*/
|
||||||
metadata?: Record<string, unknown> | null
|
raw_fulfilled_quantity: BigNumberRawValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the line item was created.
|
* The shipped quantity of the order line item.
|
||||||
*/
|
*/
|
||||||
created_at?: Date
|
shipped_quantity: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the line item was updated.
|
* The raw shipped quantity of the order line item.
|
||||||
*/
|
*/
|
||||||
updated_at?: Date
|
raw_shipped_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quantity of return requested for the order line item.
|
||||||
|
*/
|
||||||
|
return_requested_quantity: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw quantity of return requested for the order line item.
|
||||||
|
*/
|
||||||
|
raw_return_requested_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quantity of return received for the order line item.
|
||||||
|
*/
|
||||||
|
return_received_quantity: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw quantity of return received for the order line item.
|
||||||
|
*/
|
||||||
|
raw_return_received_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quantity of return dismissed for the order line item.
|
||||||
|
*/
|
||||||
|
return_dismissed_quantity: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw quantity of return dismissed for the order line item.
|
||||||
|
*/
|
||||||
|
raw_return_dismissed_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quantity of written off for the order line item.
|
||||||
|
*/
|
||||||
|
written_off_quantity: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw quantity of written off for the order line item.
|
||||||
|
*/
|
||||||
|
raw_written_off_quantity: BigNumberRawValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The summary of the order line item.
|
||||||
|
*/
|
||||||
|
summary?: ItemSummary
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date when the order line item was created.
|
||||||
|
*/
|
||||||
|
created_at: Date
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date when the order line item was last updated.
|
||||||
|
*/
|
||||||
|
updated_at: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OrderDTO {
|
export interface OrderDTO {
|
||||||
@@ -452,6 +561,10 @@ export interface OrderDTO {
|
|||||||
* @expandable
|
* @expandable
|
||||||
*/
|
*/
|
||||||
shipping_methods?: OrderShippingMethodDTO[]
|
shipping_methods?: OrderShippingMethodDTO[]
|
||||||
|
/**
|
||||||
|
* The summary of the order totals.
|
||||||
|
*/
|
||||||
|
summary?: OrderSummary
|
||||||
/**
|
/**
|
||||||
* Holds custom data in key-value pairs.
|
* Holds custom data in key-value pairs.
|
||||||
*/
|
*/
|
||||||
@@ -464,36 +577,165 @@ export interface OrderDTO {
|
|||||||
* When the order was updated.
|
* When the order was updated.
|
||||||
*/
|
*/
|
||||||
updated_at?: string | Date
|
updated_at?: string | Date
|
||||||
|
}
|
||||||
|
|
||||||
original_item_total: number
|
export interface OrderChangeDTO {
|
||||||
original_item_subtotal: number
|
/**
|
||||||
original_item_tax_total: number
|
* The ID of the order change
|
||||||
|
*/
|
||||||
|
id: string
|
||||||
|
/**
|
||||||
|
* The ID of the associated order
|
||||||
|
*/
|
||||||
|
order_id: string
|
||||||
|
/**
|
||||||
|
* The associated order
|
||||||
|
*
|
||||||
|
* @expandable
|
||||||
|
*/
|
||||||
|
order: OrderDTO
|
||||||
|
/**
|
||||||
|
* The status of the order change
|
||||||
|
*/
|
||||||
|
status: string
|
||||||
|
/**
|
||||||
|
* The requested by of the order change
|
||||||
|
*/
|
||||||
|
requested_by: string | null
|
||||||
|
/**
|
||||||
|
* When the order change was requested
|
||||||
|
*/
|
||||||
|
requested_at: Date | string | null
|
||||||
|
/**
|
||||||
|
* The confirmed by of the order change
|
||||||
|
*/
|
||||||
|
confirmed_by: string | null
|
||||||
|
/**
|
||||||
|
* When the order change was confirmed
|
||||||
|
*/
|
||||||
|
confirmed_at: Date | string | null
|
||||||
|
/**
|
||||||
|
* The declined by of the order change
|
||||||
|
*/
|
||||||
|
declined_by: string | null
|
||||||
|
/**
|
||||||
|
* The declined reason of the order change
|
||||||
|
*/
|
||||||
|
declined_reason: string | null
|
||||||
|
/**
|
||||||
|
* The metadata of the order change
|
||||||
|
*/
|
||||||
|
metadata: Record<string, unknown> | null
|
||||||
|
/**
|
||||||
|
* When the order change was declined
|
||||||
|
*/
|
||||||
|
declined_at: Date | string | null
|
||||||
|
/**
|
||||||
|
* The canceled by of the order change
|
||||||
|
*/
|
||||||
|
canceled_by: string | null
|
||||||
|
/**
|
||||||
|
* When the order change was canceled
|
||||||
|
*/
|
||||||
|
canceled_at: Date | string | null
|
||||||
|
/**
|
||||||
|
* When the order change was created
|
||||||
|
*/
|
||||||
|
created_at: Date | string
|
||||||
|
/**
|
||||||
|
* When the order change was updated
|
||||||
|
*/
|
||||||
|
updated_at: Date | string
|
||||||
|
}
|
||||||
|
|
||||||
item_total: number
|
export interface OrderChangeActionDTO {
|
||||||
item_subtotal: number
|
/**
|
||||||
item_tax_total: number
|
* The ID of the order change action
|
||||||
|
*/
|
||||||
|
id: string
|
||||||
|
/**
|
||||||
|
* The ID of the associated order change
|
||||||
|
*/
|
||||||
|
order_change_id: string
|
||||||
|
/**
|
||||||
|
* The associated order change
|
||||||
|
*
|
||||||
|
* @expandable
|
||||||
|
*/
|
||||||
|
order_change: OrderChangeDTO
|
||||||
|
/**
|
||||||
|
* The reference of the order change action
|
||||||
|
*/
|
||||||
|
reference: string
|
||||||
|
/**
|
||||||
|
* The ID of the reference
|
||||||
|
*/
|
||||||
|
reference_id: string
|
||||||
|
/**
|
||||||
|
* The action of the order change action
|
||||||
|
*/
|
||||||
|
action: Record<string, unknown>
|
||||||
|
/**
|
||||||
|
* The metadata of the order change action
|
||||||
|
*/
|
||||||
|
metadata?: Record<string, unknown> | null
|
||||||
|
/**
|
||||||
|
* The internal note of the order change action
|
||||||
|
*/
|
||||||
|
internal_note: string | null
|
||||||
|
/**
|
||||||
|
* When the order change action was created
|
||||||
|
*/
|
||||||
|
created_at: Date | string
|
||||||
|
/**
|
||||||
|
* When the order change action was updated
|
||||||
|
*/
|
||||||
|
updated_at: Date | string
|
||||||
|
}
|
||||||
|
|
||||||
original_total: number
|
export interface OrderTransactionDTO {
|
||||||
original_subtotal: number
|
/**
|
||||||
original_tax_total: number
|
* The ID of the transaction
|
||||||
|
*/
|
||||||
total: number
|
id: string
|
||||||
subtotal: number
|
/**
|
||||||
tax_total: number
|
* The ID of the associated order
|
||||||
discount_total: number
|
*/
|
||||||
raw_discount_total: any
|
order_id: string
|
||||||
discount_tax_total: number
|
/**
|
||||||
|
* The associated order
|
||||||
gift_card_total: number
|
*
|
||||||
gift_card_tax_total: number
|
* @expandable
|
||||||
|
*/
|
||||||
shipping_total: number
|
order: OrderDTO
|
||||||
shipping_subtotal: number
|
/**
|
||||||
shipping_tax_total: number
|
* The amount of the transaction
|
||||||
|
*/
|
||||||
original_shipping_total: number
|
amount: number
|
||||||
original_shipping_subtotal: number
|
/**
|
||||||
original_shipping_tax_total: number
|
* The currency code of the transaction
|
||||||
|
*/
|
||||||
|
currency_code: string
|
||||||
|
/**
|
||||||
|
* The reference of the transaction
|
||||||
|
*/
|
||||||
|
reference: string
|
||||||
|
/**
|
||||||
|
* The ID of the reference
|
||||||
|
*/
|
||||||
|
reference_id: string
|
||||||
|
/**
|
||||||
|
* The metadata of the transaction
|
||||||
|
*/
|
||||||
|
metadata: Record<string, unknown> | null
|
||||||
|
/**
|
||||||
|
* When the transaction was created
|
||||||
|
*/
|
||||||
|
created_at: Date | string
|
||||||
|
/**
|
||||||
|
* When the transaction was updated
|
||||||
|
*/
|
||||||
|
updated_at: Date | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FilterableOrderProps
|
export interface FilterableOrderProps
|
||||||
@@ -568,3 +810,31 @@ export interface FilterableOrderShippingMethodTaxLineProps
|
|||||||
shipping_method_id?: string | string[]
|
shipping_method_id?: string | string[]
|
||||||
shipping_method?: FilterableOrderShippingMethodProps
|
shipping_method?: FilterableOrderShippingMethodProps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FilterableOrderChangeProps
|
||||||
|
extends BaseFilterable<FilterableOrderChangeProps> {
|
||||||
|
id?: string | string[]
|
||||||
|
order_id?: string | string[]
|
||||||
|
status?: string | string[]
|
||||||
|
requested_by?: string | string[]
|
||||||
|
confirmed_by?: string | string[]
|
||||||
|
declined_by?: string | string[]
|
||||||
|
canceled_by?: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FilterableOrderChangeActionProps
|
||||||
|
extends BaseFilterable<FilterableOrderChangeActionProps> {
|
||||||
|
id?: string | string[]
|
||||||
|
order_change_id?: string | string[]
|
||||||
|
reference?: string | string[]
|
||||||
|
reference_id?: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FilterableOrderTransactionProps
|
||||||
|
extends BaseFilterable<FilterableOrderTransactionProps> {
|
||||||
|
id?: string | string[]
|
||||||
|
order_id?: string | string[]
|
||||||
|
currency_code?: string | string[]
|
||||||
|
reference?: string | string[]
|
||||||
|
reference_id?: string | string[]
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { BigNumberInput } from "../totals"
|
||||||
import { OrderLineItemDTO } from "./common"
|
import { OrderLineItemDTO } from "./common"
|
||||||
|
|
||||||
/** ADDRESS START */
|
/** ADDRESS START */
|
||||||
@@ -63,7 +64,7 @@ export interface UpdateOrderDTO {
|
|||||||
/** ADJUSTMENT START */
|
/** ADJUSTMENT START */
|
||||||
export interface CreateOrderAdjustmentDTO {
|
export interface CreateOrderAdjustmentDTO {
|
||||||
code: string
|
code: string
|
||||||
amount: number
|
amount: BigNumberInput
|
||||||
description?: string
|
description?: string
|
||||||
promotion_id?: string
|
promotion_id?: string
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
@@ -72,7 +73,7 @@ export interface CreateOrderAdjustmentDTO {
|
|||||||
export interface UpdateOrderAdjustmentDTO {
|
export interface UpdateOrderAdjustmentDTO {
|
||||||
id: string
|
id: string
|
||||||
code?: string
|
code?: string
|
||||||
amount: number
|
amount: BigNumberInput
|
||||||
description?: string
|
description?: string
|
||||||
promotion_id?: string
|
promotion_id?: string
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
@@ -92,7 +93,7 @@ export interface UpsertOrderLineItemAdjustmentDTO {
|
|||||||
id?: string
|
id?: string
|
||||||
item_id: string
|
item_id: string
|
||||||
code?: string
|
code?: string
|
||||||
amount?: number
|
amount?: BigNumberInput
|
||||||
description?: string
|
description?: string
|
||||||
promotion_id?: string
|
promotion_id?: string
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
@@ -106,7 +107,7 @@ export interface CreateOrderTaxLineDTO {
|
|||||||
description?: string
|
description?: string
|
||||||
tax_rate_id?: string
|
tax_rate_id?: string
|
||||||
code: string
|
code: string
|
||||||
rate: number
|
rate: BigNumberInput
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ export interface UpdateOrderTaxLineDTO {
|
|||||||
description?: string
|
description?: string
|
||||||
tax_rate_id?: string
|
tax_rate_id?: string
|
||||||
code?: string
|
code?: string
|
||||||
rate?: number
|
rate?: BigNumberInput
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ export interface CreateOrderLineItemDTO {
|
|||||||
|
|
||||||
order_id?: string
|
order_id?: string
|
||||||
|
|
||||||
quantity: number
|
quantity: BigNumberInput
|
||||||
|
|
||||||
product_id?: string
|
product_id?: string
|
||||||
product_title?: string
|
product_title?: string
|
||||||
@@ -159,8 +160,8 @@ export interface CreateOrderLineItemDTO {
|
|||||||
is_discountable?: boolean
|
is_discountable?: boolean
|
||||||
is_tax_inclusive?: boolean
|
is_tax_inclusive?: boolean
|
||||||
|
|
||||||
compare_at_unit_price?: number
|
compare_at_unit_price?: BigNumberInput
|
||||||
unit_price: number | string
|
unit_price: BigNumberInput
|
||||||
|
|
||||||
tax_lines?: CreateOrderTaxLineDTO[]
|
tax_lines?: CreateOrderTaxLineDTO[]
|
||||||
adjustments?: CreateOrderAdjustmentDTO[]
|
adjustments?: CreateOrderAdjustmentDTO[]
|
||||||
@@ -183,8 +184,8 @@ export interface UpdateOrderLineItemDTO
|
|||||||
id: string
|
id: string
|
||||||
|
|
||||||
title?: string
|
title?: string
|
||||||
quantity?: number
|
quantity?: BigNumberInput
|
||||||
unit_price?: number
|
unit_price?: BigNumberInput
|
||||||
|
|
||||||
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
|
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
|
||||||
adjustments?: UpdateOrderAdjustmentDTO[] | CreateOrderAdjustmentDTO[]
|
adjustments?: UpdateOrderAdjustmentDTO[] | CreateOrderAdjustmentDTO[]
|
||||||
@@ -197,7 +198,7 @@ export interface UpdateOrderLineItemDTO
|
|||||||
export interface CreateOrderShippingMethodDTO {
|
export interface CreateOrderShippingMethodDTO {
|
||||||
name: string
|
name: string
|
||||||
order_id: string
|
order_id: string
|
||||||
amount: number
|
amount: BigNumberInput
|
||||||
data?: Record<string, unknown>
|
data?: Record<string, unknown>
|
||||||
tax_lines?: CreateOrderTaxLineDTO[]
|
tax_lines?: CreateOrderTaxLineDTO[]
|
||||||
adjustments?: CreateOrderAdjustmentDTO[]
|
adjustments?: CreateOrderAdjustmentDTO[]
|
||||||
@@ -205,7 +206,7 @@ export interface CreateOrderShippingMethodDTO {
|
|||||||
|
|
||||||
export interface CreateOrderShippingMethodForSingleOrderDTO {
|
export interface CreateOrderShippingMethodForSingleOrderDTO {
|
||||||
name: string
|
name: string
|
||||||
amount: number
|
amount: BigNumberInput
|
||||||
data?: Record<string, unknown>
|
data?: Record<string, unknown>
|
||||||
tax_lines?: CreateOrderTaxLineDTO[]
|
tax_lines?: CreateOrderTaxLineDTO[]
|
||||||
adjustments?: CreateOrderAdjustmentDTO[]
|
adjustments?: CreateOrderAdjustmentDTO[]
|
||||||
@@ -214,7 +215,7 @@ export interface CreateOrderShippingMethodForSingleOrderDTO {
|
|||||||
export interface UpdateOrderShippingMethodDTO {
|
export interface UpdateOrderShippingMethodDTO {
|
||||||
id: string
|
id: string
|
||||||
name?: string
|
name?: string
|
||||||
amount?: number
|
amount?: BigNumberInput
|
||||||
data?: Record<string, unknown>
|
data?: Record<string, unknown>
|
||||||
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
|
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
|
||||||
adjustments?: CreateOrderAdjustmentDTO[] | UpdateOrderAdjustmentDTO[]
|
adjustments?: CreateOrderAdjustmentDTO[] | UpdateOrderAdjustmentDTO[]
|
||||||
@@ -223,7 +224,7 @@ export interface UpdateOrderShippingMethodDTO {
|
|||||||
export interface CreateOrderShippingMethodAdjustmentDTO {
|
export interface CreateOrderShippingMethodAdjustmentDTO {
|
||||||
shipping_method_id: string
|
shipping_method_id: string
|
||||||
code: string
|
code: string
|
||||||
amount: number
|
amount: BigNumberInput
|
||||||
description?: string
|
description?: string
|
||||||
promotion_id?: string
|
promotion_id?: string
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
@@ -232,10 +233,86 @@ export interface CreateOrderShippingMethodAdjustmentDTO {
|
|||||||
export interface UpdateOrderShippingMethodAdjustmentDTO {
|
export interface UpdateOrderShippingMethodAdjustmentDTO {
|
||||||
id: string
|
id: string
|
||||||
code?: string
|
code?: string
|
||||||
amount?: number
|
amount?: BigNumberInput
|
||||||
description?: string
|
description?: string
|
||||||
promotion_id?: string
|
promotion_id?: string
|
||||||
provider_id?: string
|
provider_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SHIPPING METHODS END */
|
/** SHIPPING METHODS END */
|
||||||
|
|
||||||
|
/** ORDER CHANGE START */
|
||||||
|
|
||||||
|
export interface CreateOrderChangeDTO {
|
||||||
|
order_id: string
|
||||||
|
status: string
|
||||||
|
description?: string
|
||||||
|
internal_note?: string
|
||||||
|
requested_by?: string
|
||||||
|
requested_at?: Date
|
||||||
|
confirmed_by?: string
|
||||||
|
confirmed_at?: Date
|
||||||
|
declined_by?: string
|
||||||
|
declined_reason?: string
|
||||||
|
declined_at?: Date
|
||||||
|
canceled_by?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateOrderChangeDTO {
|
||||||
|
id: string
|
||||||
|
status?: string
|
||||||
|
description?: string
|
||||||
|
internal_note?: string
|
||||||
|
requested_by?: string
|
||||||
|
requested_at?: Date
|
||||||
|
confirmed_by?: string
|
||||||
|
confirmed_at?: Date
|
||||||
|
declined_by?: string
|
||||||
|
declined_reason?: string
|
||||||
|
declined_at?: Date
|
||||||
|
canceled_by?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ORDER CHANGE END */
|
||||||
|
|
||||||
|
/** ORDER CHANGE ACTION START */
|
||||||
|
|
||||||
|
export interface CreateOrderChangeActionDTO {
|
||||||
|
order_change_id: string
|
||||||
|
reference: string
|
||||||
|
reference_id: string
|
||||||
|
action: Record<string, unknown>
|
||||||
|
internal_note?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateOrderChangeActionDTO {
|
||||||
|
id: string
|
||||||
|
reference?: string
|
||||||
|
reference_id?: string
|
||||||
|
action?: Record<string, unknown>
|
||||||
|
internal_note?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ORDER TRANSACTION START */
|
||||||
|
|
||||||
|
export interface CreateOrderTransactionDTO {
|
||||||
|
order_id: string
|
||||||
|
amount: BigNumberInput
|
||||||
|
currency_code: string
|
||||||
|
reference?: string
|
||||||
|
reference_id?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateOrderTransactionDTO {
|
||||||
|
id: string
|
||||||
|
amount?: BigNumberInput
|
||||||
|
currency_code?: string
|
||||||
|
reference?: string
|
||||||
|
reference_id?: string
|
||||||
|
metadata?: Record<string, unknown>
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from "./mikro-orm/big-number-field"
|
||||||
export * from "./mikro-orm/mikro-orm-create-connection"
|
export * from "./mikro-orm/mikro-orm-create-connection"
|
||||||
export * from "./mikro-orm/mikro-orm-repository"
|
export * from "./mikro-orm/mikro-orm-repository"
|
||||||
export * from "./mikro-orm/mikro-orm-soft-deletable-filter"
|
export * from "./mikro-orm/mikro-orm-soft-deletable-filter"
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import { BigNumber } from "../../totals/big-number"
|
||||||
|
|
||||||
|
const bigNumberFields = new WeakMap<
|
||||||
|
object,
|
||||||
|
{ prop: string; options: { nullable?: boolean } }[]
|
||||||
|
>()
|
||||||
|
|
||||||
|
export function BigNumberField(options: { nullable?: boolean } = {}) {
|
||||||
|
return function (target: any, prop: string) {
|
||||||
|
const entity = target.constructor
|
||||||
|
if (!bigNumberFields.has(entity)) {
|
||||||
|
bigNumberFields.set(entity, [])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prop.startsWith("raw_")) {
|
||||||
|
const suggestedPropName = prop.replace("raw_", "")
|
||||||
|
throw new Error(
|
||||||
|
`BigNumberField decorator has to be used on the property "${suggestedPropName}" and ${prop} typed as BigNumberRawValue.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
bigNumberFields.get(entity)?.push({ prop, options })
|
||||||
|
|
||||||
|
if (!entity.prototype.__bigNumberInitialized) {
|
||||||
|
entity.prototype.__bigNumberInitialized = true
|
||||||
|
|
||||||
|
registerGlobalHook(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerGlobalHook(entity: any) {
|
||||||
|
const originalOnInit = entity.prototype.onInit
|
||||||
|
const originalOnCreate = entity.prototype.onCreate
|
||||||
|
const originalOnUpdate = entity.prototype.onUpdate
|
||||||
|
|
||||||
|
entity.prototype.onInit = function (...args: any[]) {
|
||||||
|
initializeBigNumberFields(this)
|
||||||
|
|
||||||
|
if (originalOnInit) {
|
||||||
|
originalOnInit.apply(this, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.prototype.onCreate = function (...args: any[]) {
|
||||||
|
initializeBigNumberFields(this)
|
||||||
|
|
||||||
|
if (originalOnCreate) {
|
||||||
|
originalOnCreate.apply(this, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.prototype.onUpdate = function (...args: any[]) {
|
||||||
|
initializeBigNumberFields(this)
|
||||||
|
|
||||||
|
if (originalOnUpdate) {
|
||||||
|
originalOnUpdate.apply(this, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeBigNumberFields(entity: any) {
|
||||||
|
const fields = bigNumberFields.get(entity.constructor) ?? []
|
||||||
|
|
||||||
|
for (const field of fields) {
|
||||||
|
const { prop, options } = field
|
||||||
|
|
||||||
|
const rawValue = entity[`raw_${prop}`]
|
||||||
|
const value = entity[prop]
|
||||||
|
if (options.nullable && rawValue === null && value === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const val = new BigNumber(rawValue ?? value)
|
||||||
|
entity[prop] = val.numeric
|
||||||
|
entity[`raw_${prop}`] = val.raw
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,3 +29,31 @@ export enum OrderStatus {
|
|||||||
*/
|
*/
|
||||||
REQUIRES_ACTION = "requires_action",
|
REQUIRES_ACTION = "requires_action",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum
|
||||||
|
*
|
||||||
|
* The order change's status.
|
||||||
|
*/
|
||||||
|
export enum OrderChangeStatus {
|
||||||
|
/**
|
||||||
|
* The order change is confirmed.
|
||||||
|
*/
|
||||||
|
CONFIRMED = "confirmed",
|
||||||
|
/**
|
||||||
|
* The order change is declined.
|
||||||
|
*/
|
||||||
|
DECLINED = "declined",
|
||||||
|
/**
|
||||||
|
* The order change is requested.
|
||||||
|
*/
|
||||||
|
REQUESTED = "requested",
|
||||||
|
/**
|
||||||
|
* The order change is pending.
|
||||||
|
*/
|
||||||
|
PENDING = "pending",
|
||||||
|
/**
|
||||||
|
* The order change is canceled.
|
||||||
|
*/
|
||||||
|
CANCELED = "canceled",
|
||||||
|
}
|
||||||
Reference in new issue
Block a user