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
+360 -90
View File
@@ -1,5 +1,41 @@
import { BaseFilterable } from "../dal"
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 {
/**
@@ -251,10 +287,6 @@ export interface OrderShippingMethodDTO {
*/
updated_at: Date | string
original_total: number
original_subtotal: number
original_tax_total: number
total: number
subtotal: number
tax_total: number
@@ -280,127 +312,204 @@ export interface OrderLineItemTotalsDTO {
export interface OrderLineItemDTO extends OrderLineItemTotalsDTO {
/**
* The ID of the line item.
* The ID of the order line item.
*/
id: string
/**
* The title of the line item.
* The title of the order line item.
*/
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.
*/
variant_option_values?: Record<string, unknown>
/**
* Whether the line item requires shipping or not
* Indicates whether the order line item requires shipping.
*/
requires_shipping: boolean
/**
* Whether the line item is discountable or not
* Indicates whether the order line item is discountable.
*/
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
/**
* 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
/**
* 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
/**
* The associated tax lines.
*
* @expandable
* The raw unit price of the order line item.
*/
tax_lines?: OrderLineItemTaxLineDTO[]
raw_unit_price: BigNumberRawValue
/**
* The associated adjustments.
*
* @expandable
* The quantity of the order line item.
*/
adjustments?: OrderLineItemAdjustmentDTO[]
quantity: number
/**
* The associated order.
*
* @expandable
* The raw quantity of the order line item.
*/
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 {
@@ -452,6 +561,10 @@ export interface OrderDTO {
* @expandable
*/
shipping_methods?: OrderShippingMethodDTO[]
/**
* The summary of the order totals.
*/
summary?: OrderSummary
/**
* Holds custom data in key-value pairs.
*/
@@ -464,36 +577,165 @@ export interface OrderDTO {
* When the order was updated.
*/
updated_at?: string | Date
}
original_item_total: number
original_item_subtotal: number
original_item_tax_total: number
export interface OrderChangeDTO {
/**
* 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
item_subtotal: number
item_tax_total: number
export interface OrderChangeActionDTO {
/**
* 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
original_subtotal: number
original_tax_total: number
total: number
subtotal: number
tax_total: number
discount_total: number
raw_discount_total: any
discount_tax_total: number
gift_card_total: number
gift_card_tax_total: number
shipping_total: number
shipping_subtotal: number
shipping_tax_total: number
original_shipping_total: number
original_shipping_subtotal: number
original_shipping_tax_total: number
export interface OrderTransactionDTO {
/**
* The ID of the transaction
*/
id: string
/**
* The ID of the associated order
*/
order_id: string
/**
* The associated order
*
* @expandable
*/
order: OrderDTO
/**
* The amount of the transaction
*/
amount: 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
@@ -568,3 +810,31 @@ export interface FilterableOrderShippingMethodTaxLineProps
shipping_method_id?: string | string[]
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[]
}
+92 -15
View File
@@ -1,3 +1,4 @@
import { BigNumberInput } from "../totals"
import { OrderLineItemDTO } from "./common"
/** ADDRESS START */
@@ -63,7 +64,7 @@ export interface UpdateOrderDTO {
/** ADJUSTMENT START */
export interface CreateOrderAdjustmentDTO {
code: string
amount: number
amount: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
@@ -72,7 +73,7 @@ export interface CreateOrderAdjustmentDTO {
export interface UpdateOrderAdjustmentDTO {
id: string
code?: string
amount: number
amount: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
@@ -92,7 +93,7 @@ export interface UpsertOrderLineItemAdjustmentDTO {
id?: string
item_id: string
code?: string
amount?: number
amount?: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
@@ -106,7 +107,7 @@ export interface CreateOrderTaxLineDTO {
description?: string
tax_rate_id?: string
code: string
rate: number
rate: BigNumberInput
provider_id?: string
}
@@ -115,7 +116,7 @@ export interface UpdateOrderTaxLineDTO {
description?: string
tax_rate_id?: string
code?: string
rate?: number
rate?: BigNumberInput
provider_id?: string
}
@@ -139,7 +140,7 @@ export interface CreateOrderLineItemDTO {
order_id?: string
quantity: number
quantity: BigNumberInput
product_id?: string
product_title?: string
@@ -159,8 +160,8 @@ export interface CreateOrderLineItemDTO {
is_discountable?: boolean
is_tax_inclusive?: boolean
compare_at_unit_price?: number
unit_price: number | string
compare_at_unit_price?: BigNumberInput
unit_price: BigNumberInput
tax_lines?: CreateOrderTaxLineDTO[]
adjustments?: CreateOrderAdjustmentDTO[]
@@ -183,8 +184,8 @@ export interface UpdateOrderLineItemDTO
id: string
title?: string
quantity?: number
unit_price?: number
quantity?: BigNumberInput
unit_price?: BigNumberInput
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
adjustments?: UpdateOrderAdjustmentDTO[] | CreateOrderAdjustmentDTO[]
@@ -197,7 +198,7 @@ export interface UpdateOrderLineItemDTO
export interface CreateOrderShippingMethodDTO {
name: string
order_id: string
amount: number
amount: BigNumberInput
data?: Record<string, unknown>
tax_lines?: CreateOrderTaxLineDTO[]
adjustments?: CreateOrderAdjustmentDTO[]
@@ -205,7 +206,7 @@ export interface CreateOrderShippingMethodDTO {
export interface CreateOrderShippingMethodForSingleOrderDTO {
name: string
amount: number
amount: BigNumberInput
data?: Record<string, unknown>
tax_lines?: CreateOrderTaxLineDTO[]
adjustments?: CreateOrderAdjustmentDTO[]
@@ -214,7 +215,7 @@ export interface CreateOrderShippingMethodForSingleOrderDTO {
export interface UpdateOrderShippingMethodDTO {
id: string
name?: string
amount?: number
amount?: BigNumberInput
data?: Record<string, unknown>
tax_lines?: UpdateOrderTaxLineDTO[] | CreateOrderTaxLineDTO[]
adjustments?: CreateOrderAdjustmentDTO[] | UpdateOrderAdjustmentDTO[]
@@ -223,7 +224,7 @@ export interface UpdateOrderShippingMethodDTO {
export interface CreateOrderShippingMethodAdjustmentDTO {
shipping_method_id: string
code: string
amount: number
amount: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
@@ -232,10 +233,86 @@ export interface CreateOrderShippingMethodAdjustmentDTO {
export interface UpdateOrderShippingMethodAdjustmentDTO {
id: string
code?: string
amount?: number
amount?: BigNumberInput
description?: string
promotion_id?: string
provider_id?: string
}
/** 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>
}