Feat(order): order changes (#6435)

What:
 - Order DB schema migration
 - BigNumberField Decorator
  
![order_schema](https://github.com/medusajs/medusa/assets/37986729/64ec82ca-5c28-46ef-9a57-614c5a4d25f6)
This commit is contained in:
Carlos R. L. Rodrigues
2024-02-20 23:07:57 +00:00
committed by GitHub
parent 137cc0ebf8
commit 56b0b45304
33 changed files with 3848 additions and 257 deletions
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)
}
}
+2 -2
View File
@@ -14,7 +14,7 @@ import {
type OptionalAddressProps = DAL.EntityDateColumns
const customerIdIndex = createPsqlIndexStatementHelper({
const CustomerIdIndex = createPsqlIndexStatementHelper({
tableName: "order_address",
columns: "customer_id",
})
@@ -27,7 +27,7 @@ export default class Address {
id!: string
@Property({ columnType: "text", nullable: true })
@customerIdIndex.MikroORMIndex()
@CustomerIdIndex.MikroORMIndex()
customer_id: string | null = null
@Property({ columnType: "text", nullable: true })
+2 -1
View File
@@ -1,5 +1,5 @@
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"
type OptionalAdjustmentLineProps = DAL.EntityDateColumns
@@ -27,6 +27,7 @@ export default abstract class AdjustmentLine {
code: string | null = null
@Property({ columnType: "numeric" })
@BigNumberField()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
+4
View File
@@ -3,6 +3,10 @@ export { default as LineItem } from "./line-item"
export { default as LineItemAdjustment } from "./line-item-adjustment"
export { default as LineItemTaxLine } from "./line-item-tax-line"
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 ShippingMethodAdjustment } from "./shipping-method-adjustment"
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 {
BeforeCreate,
Cascade,
@@ -11,6 +14,11 @@ import {
import AdjustmentLine from "./adjustment-line"
import LineItem from "./line-item"
const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_line_item_adjustment",
columns: "item_id",
})
@Entity({ tableName: "order_line_item_adjustment" })
@Check<LineItemAdjustment>({
expression: (columns) => `${columns.amount} >= 0`,
@@ -18,12 +26,12 @@ import LineItem from "./line-item"
export default class LineItemAdjustment extends AdjustmentLine {
@ManyToOne({
entity: () => LineItem,
index: "IDX_order_line_item_adjustment_item_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
item: LineItem
@Property({ columnType: "text" })
@ItemIdIndex.MikroORMIndex()
item_id: string
@BeforeCreate()
@@ -1,4 +1,7 @@
import { generateEntityId } from "@medusajs/utils"
import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
@@ -10,16 +13,21 @@ import {
import LineItem from "./line-item"
import TaxLine from "./tax-line"
const ItemIdIndex = createPsqlIndexStatementHelper({
tableName: "order_line_item_tax_line",
columns: "item_id",
})
@Entity({ tableName: "order_line_item_tax_line" })
export default class LineItemTaxLine extends TaxLine {
@ManyToOne({
entity: () => LineItem,
index: "IDX_order_line_item_tax_line_item_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
item: LineItem
@Property({ columnType: "text" })
@ItemIdIndex.MikroORMIndex()
item_id: string
@BeforeCreate()
+10 -37
View File
@@ -1,12 +1,12 @@
import { BigNumberRawValue, DAL } from "@medusajs/types"
import {
BigNumber,
BigNumberField,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
BeforeUpdate,
Cascade,
Collection,
Entity,
@@ -19,22 +19,21 @@ import {
} from "@mikro-orm/core"
import LineItemAdjustment from "./line-item-adjustment"
import LineItemTaxLine from "./line-item-tax-line"
import Order from "./order"
import OrderDetail from "./order-detail"
type OptionalLineItemProps =
| "is_discoutable"
| "is_tax_inclusive"
| "compare_at_unit_price"
| "requires_shipping"
| "order"
| DAL.EntityDateColumns
const productIdIndex = createPsqlIndexStatementHelper({
const ProductIdIndex = createPsqlIndexStatementHelper({
tableName: "order_line_item",
columns: "product_id",
})
const variantIdIndex = createPsqlIndexStatementHelper({
const VariantIdIndex = createPsqlIndexStatementHelper({
tableName: "order_line_item",
columns: "variant_id",
})
@@ -46,16 +45,12 @@ export default class LineItem {
@PrimaryKey({ columnType: "text" })
id: string
@Property({ columnType: "text" })
order_id: string
@ManyToOne({
entity: () => Order,
entity: () => OrderDetail,
onDelete: "cascade",
index: "IDX_order_line_item_order_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
order: Order
totals: OrderDetail
@Property({ columnType: "text" })
title: string
@@ -66,24 +61,18 @@ export default class LineItem {
@Property({ columnType: "text", nullable: true })
thumbnail: string | null = null
@Property({ columnType: "numeric" })
quantity: BigNumber | number
@Property({ columnType: "jsonb" })
raw_quantity: BigNumberRawValue
@Property({
columnType: "text",
nullable: true,
})
@variantIdIndex.MikroORMIndex()
@VariantIdIndex.MikroORMIndex()
variant_id: string | null = null
@Property({
columnType: "text",
nullable: true,
})
@productIdIndex.MikroORMIndex()
@ProductIdIndex.MikroORMIndex()
product_id: string | null = null
@Property({ columnType: "text", nullable: true })
@@ -126,12 +115,14 @@ export default class LineItem {
is_tax_inclusive = false
@Property({ columnType: "numeric", nullable: true })
@BigNumberField({ nullable: true })
compare_at_unit_price?: BigNumber | number | null = null
@Property({ columnType: "jsonb", nullable: true })
raw_compare_at_unit_price: BigNumberRawValue | null = null
@Property({ columnType: "numeric" })
@BigNumberField()
unit_price: BigNumber | number
@Property({ columnType: "jsonb" })
@@ -165,28 +156,10 @@ export default class LineItem {
@BeforeCreate()
onCreate() {
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() {
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")
}
}
+140
View File
@@ -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")
}
}
+136
View File
@@ -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")
}
}
+56 -15
View File
@@ -17,45 +17,65 @@ import {
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { OrderSummary } from "../types/common"
import Address from "./address"
import LineItem from "./line-item"
import OrderDetail from "./order-detail"
import ShippingMethod from "./shipping-method"
import Transaction from "./transaction"
type OptionalOrderProps =
| "shipping_address"
| "billing_address"
| DAL.EntityDateColumns
const regionIdIndex = createPsqlIndexStatementHelper({
const RegionIdIndex = createPsqlIndexStatementHelper({
tableName: "order",
columns: "region_id",
where: "deleted_at IS NOT NULL",
})
const customerIdIndex = createPsqlIndexStatementHelper({
const CustomerIdIndex = createPsqlIndexStatementHelper({
tableName: "order",
columns: "customer_id",
where: "deleted_at IS NOT NULL",
})
const salesChannelIdIndex = createPsqlIndexStatementHelper({
const SalesChannelIdIndex = createPsqlIndexStatementHelper({
tableName: "order",
columns: "customer_id",
where: "deleted_at IS NOT NULL",
})
const orderDeletedAtIndex = createPsqlIndexStatementHelper({
const OrderDeletedAtIndex = createPsqlIndexStatementHelper({
tableName: "order",
columns: "deleted_at",
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",
columns: "currency_code",
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" })
export default class Order {
[OptionalProps]?: OptionalOrderProps
@@ -67,21 +87,34 @@ export default class Order {
columnType: "text",
nullable: true,
})
@regionIdIndex.MikroORMIndex()
@RegionIdIndex.MikroORMIndex()
region_id: string | null = null
@Property({
columnType: "text",
nullable: true,
})
@customerIdIndex.MikroORMIndex()
@CustomerIdIndex.MikroORMIndex()
customer_id: string | null = null
@Property({
columnType: "text",
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
@Enum({ items: () => OrderStatus, default: OrderStatus.PENDING })
@@ -91,29 +124,29 @@ export default class Order {
email: string | null = null
@Property({ columnType: "text" })
@currencyCodeIndex.MikroORMIndex()
@CurrencyCodeIndex.MikroORMIndex()
currency_code: string
@Property({ columnType: "text", nullable: true })
@ShippingAddressIdIndex.MikroORMIndex()
shipping_address_id?: string | null
@ManyToOne({
entity: () => Address,
fieldName: "shipping_address_id",
nullable: true,
index: "IDX_order_shipping_address_id",
cascade: [Cascade.PERSIST],
})
shipping_address?: Address | null
@Property({ columnType: "text", nullable: true })
@BillingAddressIdIndex.MikroORMIndex()
billing_address_id?: string | null
@ManyToOne({
entity: () => Address,
fieldName: "billing_address_id",
nullable: true,
index: "IDX_order_billing_address_id",
cascade: [Cascade.PERSIST],
})
billing_address?: Address | null
@@ -121,19 +154,27 @@ export default class Order {
@Property({ columnType: "boolean", nullable: true })
no_notification: boolean | null = null
@Property({ columnType: "jsonb" })
summary: OrderSummary | null = {} as OrderSummary
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@OneToMany(() => LineItem, (lineItem) => lineItem.order, {
@OneToMany(() => OrderDetail, (itemDetail) => itemDetail.order, {
cascade: [Cascade.REMOVE],
})
items = new Collection<LineItem>(this)
items = new Collection<OrderDetail>(this)
@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.order, {
cascade: [Cascade.REMOVE],
})
shipping_methods = new Collection<ShippingMethod>(this)
@OneToMany(() => Transaction, (transaction) => transaction.order, {
cascade: [Cascade.REMOVE],
})
transactions = new Collection<Transaction>(this)
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
@@ -150,7 +191,7 @@ export default class Order {
updated_at: Date
@Property({ columnType: "timestamptz", nullable: true })
@orderDeletedAtIndex.MikroORMIndex()
@OrderDeletedAtIndex.MikroORMIndex()
deleted_at: Date | null = null
@Property({ columnType: "timestamptz", nullable: true })
@@ -1,4 +1,7 @@
import { generateEntityId } from "@medusajs/utils"
import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
@@ -10,17 +13,22 @@ import {
import AdjustmentLine from "./adjustment-line"
import ShippingMethod from "./shipping-method"
const ShippingMethodIdIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping_method_adjustment",
columns: "shipping_method_id",
})
@Entity({ tableName: "order_shipping_method_adjustment" })
export default class ShippingMethodAdjustment extends AdjustmentLine {
@ManyToOne({
entity: () => ShippingMethod,
fieldName: "shipping_method_id",
index: "IDX_order_shipping_method_adjustment_shipping_method_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
shipping_method: ShippingMethod
@Property({ columnType: "text" })
@ShippingMethodIdIdIndex.MikroORMIndex()
shipping_method_id: string
@BeforeCreate()
@@ -1,4 +1,7 @@
import { generateEntityId } from "@medusajs/utils"
import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
@@ -10,17 +13,22 @@ import {
import ShippingMethod from "./shipping-method"
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" })
export default class ShippingMethodTaxLine extends TaxLine {
@ManyToOne({
entity: () => ShippingMethod,
fieldName: "shipping_method_id",
index: "IDX_order_tax_line_shipping_method_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
shipping_method: ShippingMethod
@Property({ columnType: "text" })
@ShippingMethodIdIdIndex.MikroORMIndex()
shipping_method_id: string
@BeforeCreate()
+10 -23
View File
@@ -1,6 +1,7 @@
import { BigNumberRawValue } from "@medusajs/types"
import {
BigNumber,
BigNumberField,
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
@@ -16,16 +17,20 @@ import {
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { BeforeUpdate } from "typeorm"
import Order from "./order"
import ShippingMethodAdjustment from "./shipping-method-adjustment"
import ShippingMethodTaxLine from "./shipping-method-tax-line"
const shippingOptionIdIndex = createPsqlIndexStatementHelper({
const ShippingOptionIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping_method",
columns: "shipping_option_id",
})
const OrderIdIndex = createPsqlIndexStatementHelper({
tableName: "order_shipping_method",
columns: "order_id",
})
@Entity({ tableName: "order_shipping_method" })
@Check<ShippingMethod>({ expression: (columns) => `${columns.amount} >= 0` })
export default class ShippingMethod {
@@ -33,12 +38,12 @@ export default class ShippingMethod {
id: string
@Property({ columnType: "text" })
@OrderIdIndex.MikroORMIndex()
order_id: string
@ManyToOne({
entity: () => Order,
fieldName: "order_id",
index: "IDX_order_shipping_method_order_id",
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
order: Order
@@ -50,6 +55,7 @@ export default class ShippingMethod {
description: string | null = null
@Property({ columnType: "numeric" })
@BigNumberField()
amount: BigNumber | number
@Property({ columnType: "jsonb" })
@@ -62,7 +68,7 @@ export default class ShippingMethod {
columnType: "text",
nullable: true,
})
@shippingOptionIdIndex.MikroORMIndex()
@ShippingOptionIdIndex.MikroORMIndex()
shipping_option_id: string | null = null
@Property({ columnType: "jsonb", nullable: true })
@@ -107,28 +113,9 @@ export default class ShippingMethod {
@BeforeCreate()
onCreate() {
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() {
this.id = generateEntityId(this.id, "ordsm")
const val = new BigNumber(this.raw_amount ?? this.amount)
this.amount = val.numeric
this.raw_amount = val.raw!
}
}
+2 -1
View File
@@ -1,5 +1,5 @@
import { BigNumberRawValue } from "@medusajs/types"
import { BigNumber } from "@medusajs/utils"
import { BigNumber, BigNumberField } from "@medusajs/utils"
import { PrimaryKey, Property } from "@mikro-orm/core"
/**
@@ -23,6 +23,7 @@ export default abstract class TaxLine {
code: string
@Property({ columnType: "numeric" })
@BigNumberField()
rate: BigNumber | number
@Property({ columnType: "jsonb" })
+103
View File
@@ -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,
LineItemTaxLine,
Order,
OrderChange,
OrderChangeAction,
OrderDetail,
ShippingMethod,
ShippingMethodAdjustment,
ShippingMethodTaxLine,
Transaction,
} from "@models"
import {
CreateOrderLineItemDTO,
@@ -48,6 +52,10 @@ type InjectedDependencies = {
lineItemAdjustmentService: ModulesSdkTypes.InternalModuleService<any>
lineItemTaxLineService: 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 = [
@@ -58,6 +66,10 @@ const generateMethodForModels = [
ShippingMethod,
ShippingMethodAdjustment,
ShippingMethodTaxLine,
Transaction,
OrderChange,
OrderChangeAction,
OrderDetail,
]
export default class OrderModuleService<
@@ -68,7 +80,11 @@ export default class OrderModuleService<
TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine,
TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment,
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<
InjectedDependencies,
@@ -83,6 +99,9 @@ export default class OrderModuleService<
dto: OrderTypes.OrderShippingMethodAdjustmentDTO
}
ShippingMethodTaxLine: { dto: OrderTypes.OrderShippingMethodTaxLineDTO }
Transaction: { dto: OrderTypes.OrderTransactionDTO }
Change: { dto: OrderTypes.OrderChangeDTO }
ChangeAction: { dto: OrderTypes.OrderChangeActionDTO }
}
>(Order, generateMethodForModels, entityNameToLinkableKeysMap)
implements IOrderModuleService
@@ -96,6 +115,10 @@ export default class OrderModuleService<
protected lineItemAdjustmentService_: ModulesSdkTypes.InternalModuleService<TLineItemAdjustment>
protected lineItemTaxLineService_: ModulesSdkTypes.InternalModuleService<TLineItemTaxLine>
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(
{
@@ -108,6 +131,10 @@ export default class OrderModuleService<
lineItemAdjustmentService,
shippingMethodTaxLineService,
lineItemTaxLineService,
transactionService,
orderChangeService,
orderChangeActionService,
orderDetailService,
}: InjectedDependencies,
protected readonly moduleDeclaration: InternalModuleDeclaration
) {
@@ -123,6 +150,10 @@ export default class OrderModuleService<
this.lineItemAdjustmentService_ = lineItemAdjustmentService
this.shippingMethodTaxLineService_ = shippingMethodTaxLineService
this.lineItemTaxLineService_ = lineItemTaxLineService
this.transactionService_ = transactionService
this.orderChangeService_ = orderChangeService
this.orderChangeActionService_ = orderChangeActionService
this.orderDetailService_ = orderDetailService
}
__joinerConfig(): ModuleJoinerConfig {
@@ -1,8 +0,0 @@
import { BigNumberInput } from "@medusajs/types"
export interface UpdateOrderShippingMethodDTO {
id: string
name?: string
amount?: BigNumberInput
data?: Record<string, unknown>
}
+5 -14
View File
@@ -1,20 +1,11 @@
export interface UpsertOrderAddressDTO {
customer_id?: string
company?: string
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>
}
import { OrderTypes } from "@medusajs/types"
export type UpsertOrderAddressDTO = OrderTypes.UpsertOrderAddressDTO
export interface UpdateOrderAddressDTO extends UpsertOrderAddressDTO {
id: string
}
export interface CreateOrderAddressDTO extends UpsertOrderAddressDTO {}
export type OrderAddressDTO = OrderTypes.OrderAddressDTO
+36
View File
@@ -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
}
+1
View File
@@ -8,6 +8,7 @@ export * from "./order"
export * from "./shipping-method"
export * from "./shipping-method-adjustment"
export * from "./shipping-method-tax-line"
export * from "./transaction"
export type InitializeModuleInjectableDependencies = {
logger?: Logger
@@ -1,13 +1,7 @@
import { BigNumberInput } from "@medusajs/types"
import { OrderTypes } from "@medusajs/types"
export interface CreateOrderLineItemAdjustmentDTO {
item_id: string
amount: BigNumberInput
code?: string
description?: string
promotion_id?: string
provider_id?: string
}
export type CreateOrderLineItemAdjustmentDTO =
OrderTypes.CreateOrderLineItemAdjustmentDTO
export interface UpdateOrderLineItemAdjustmentDTO
extends Partial<CreateOrderLineItemAdjustmentDTO> {
+1
View File
@@ -17,6 +17,7 @@ export interface CreateOrderDTO {
export interface UpdateOrderDTO {
id: string
version?: number
region_id?: string
customer_id?: string
sales_channel_id?: string
@@ -1,19 +1,7 @@
import { BigNumberInput } from "@medusajs/types"
import { OrderTypes } from "@medusajs/types"
export interface CreateOrderShippingMethodAdjustmentDTO {
shipping_method_id: string
code: string
amount: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
}
export type CreateOrderShippingMethodAdjustmentDTO =
OrderTypes.CreateOrderShippingMethodAdjustmentDTO
export interface UpdateOrderShippingMethodAdjustmentDTO {
id: string
code?: string
amount?: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
}
export type UpdateOrderShippingMethodAdjustmentDTO =
OrderTypes.UpdateOrderShippingMethodAdjustmentDTO
+3 -16
View File
@@ -1,18 +1,5 @@
import { BigNumberInput } from "@medusajs/types"
import { OrderTypes } from "@medusajs/types"
export interface UpdateOrderTaxLineDTO {
id: string
description?: string
tax_rate_id?: string
code?: string
rate?: BigNumberInput
provider_id?: string
}
export type CreateOrderTaxLineDTO = OrderTypes.CreateOrderTaxLineDTO
export interface CreateOrderTaxLineDTO {
description?: string
tax_rate_id?: string
code: string
rate: BigNumberInput
provider_id?: string
}
export type UpdateOrderTaxLineDTO = OrderTypes.UpdateOrderTaxLineDTO
+3
View File
@@ -0,0 +1,3 @@
import { OrderTypes } from "@medusajs/types"
export type OrderTransactionDTO = OrderTypes.OrderTransactionDTO