feat(order): create claim and exchange (#7734)

This commit is contained in:
Carlos R. L. Rodrigues
2024-06-18 08:08:16 -03:00
committed by GitHub
parent e0b14519f1
commit cfa983001b
45 changed files with 2571 additions and 437 deletions
-1
View File
@@ -26,7 +26,6 @@
"cross-env": "^5.2.1",
"ioredis": "^5.2.5",
"rimraf": "^5.0.1",
"typeorm": "^0.3.16",
"typescript": "^5.1.6",
"vite": "^5.2.11",
"winston": "^3.8.2"
+35 -1
View File
@@ -2,7 +2,7 @@ import { BaseFilterable } from "../dal"
import { OperatorMap } from "../dal/utils"
import { FulfillmentDTO } from "../fulfillment"
import { PaymentCollectionDTO } from "../payment"
import { BigNumberRawValue, BigNumberValue } from "../totals"
import { BigNumberInput, BigNumberRawValue, BigNumberValue } from "../totals"
export type ChangeActionType =
| "CANCEL"
@@ -1113,6 +1113,25 @@ type ReturnStatus = "requested" | "received" | "partially_received" | "canceled"
export interface ReturnDTO extends Omit<OrderDTO, "status" | "version"> {
status: ReturnStatus
refund_amount?: BigNumberValue
}
export interface OrderClaimDTO
extends Omit<OrderDTO, "status" | "version" | "items"> {
claim_items: any[]
additional_items: any[]
return?: ReturnDTO
no_notification?: boolean
refund_amount?: BigNumberValue
}
export interface OrderExchangeDTO
extends Omit<OrderDTO, "status" | "version" | "items"> {
return_items: any[]
additional_items: any[]
no_notification?: boolean
difference_due?: BigNumberValue
return?: ReturnDTO
}
export type PaymentStatus =
@@ -1531,3 +1550,18 @@ export interface FilterableOrderReturnReasonProps {
label?: string
description?: string
}
export interface OrderChangeReturn {
items: {
item_id: string
order_id: string
fulfilled_quantity: BigNumberInput
shipped_quantity: BigNumberInput
return_requested_quantity: BigNumberInput
return_received_quantity: BigNumberInput
return_dismissed_quantity: BigNumberInput
written_off_quantity: BigNumberInput
[key: string]: any
}[]
shippingMethods: any[]
}
+44 -2
View File
@@ -379,6 +379,7 @@ interface BaseOrderBundledItemActionsDTO {
id: string
quantity: BigNumberInput
internal_note?: string
note?: string
metadata?: Record<string, unknown> | null
}
interface BaseOrderBundledActionsDTO {
@@ -406,11 +407,52 @@ export interface CancelOrderFulfillmentDTO extends BaseOrderBundledActionsDTO {
export interface RegisterOrderShipmentDTO extends BaseOrderBundledActionsDTO {
items: BaseOrderBundledItemActionsDTO[]
no_notification?: boolean
}
export interface CreateOrderReturnDTO extends BaseOrderBundledActionsDTO {
items: BaseOrderBundledItemActionsDTO[]
shipping_method: Omit<CreateOrderShippingMethodDTO, "order_id"> | string
items: {
id: string
quantity: BigNumberInput
internal_note?: string
note?: string
reason_id?: string
metadata?: Record<string, any>
}[]
shipping_method?: Omit<CreateOrderShippingMethodDTO, "order_id"> | string
refund_amount?: BigNumberInput
no_notification?: boolean
}
export type OrderClaimType = "refund" | "replace"
export type ClaimReason =
| "missing_item"
| "wrong_item"
| "production_failure"
| "other"
export interface CreateOrderClaimDTO extends BaseOrderBundledActionsDTO {
type: OrderClaimType
claim_items: (BaseOrderBundledItemActionsDTO & {
reason: ClaimReason
images?: {
url: string
metadata?: Record<string, any>
}[]
})[]
additional_items?: BaseOrderBundledItemActionsDTO[]
shipping_methods?: Omit<CreateOrderShippingMethodDTO, "order_id">[] | string[]
return_shipping?: Omit<CreateOrderShippingMethodDTO, "order_id"> | string
refund_amount?: BigNumberInput
no_notification?: boolean
}
export interface CreateOrderExchangeDTO extends BaseOrderBundledActionsDTO {
additional_items?: BaseOrderBundledItemActionsDTO[]
shipping_methods?: Omit<CreateOrderShippingMethodDTO, "order_id">[] | string[]
return_shipping: Omit<CreateOrderShippingMethodDTO, "order_id"> | string
difference_due?: BigNumberInput
allow_backorder?: boolean
no_notification?: boolean
}
export interface CancelOrderReturnDTO {
+60 -6
View File
@@ -16,7 +16,10 @@ import {
OrderAddressDTO,
OrderChangeActionDTO,
OrderChangeDTO,
OrderChangeReturn,
OrderClaimDTO,
OrderDTO,
OrderExchangeDTO,
OrderItemDTO,
OrderLineItemAdjustmentDTO,
OrderLineItemDTO,
@@ -36,7 +39,9 @@ import {
CreateOrderAdjustmentDTO,
CreateOrderChangeActionDTO,
CreateOrderChangeDTO,
CreateOrderClaimDTO,
CreateOrderDTO,
CreateOrderExchangeDTO,
CreateOrderLineItemDTO,
CreateOrderLineItemForOrderDTO,
CreateOrderLineItemTaxLineDTO,
@@ -149,6 +154,42 @@ export interface IOrderModuleService extends IModuleService {
sharedContext?: Context
): Promise<[ReturnDTO[], number]>
retrieveOrderClaim(
claimnId: string,
config?: FindConfig<OrderClaimDTO>,
sharedContext?: Context
): Promise<OrderClaimDTO>
listOrderClaims(
filters?: FilterableOrderProps,
config?: FindConfig<OrderClaimDTO>,
sharedContext?: Context
): Promise<OrderClaimDTO[]>
listAndCountOrderClaims(
filters?: FilterableOrderProps,
config?: FindConfig<OrderClaimDTO>,
sharedContext?: Context
): Promise<[OrderClaimDTO[], number]>
retrieveOrderExchange(
claimnId: string,
config?: FindConfig<OrderExchangeDTO>,
sharedContext?: Context
): Promise<OrderExchangeDTO>
listOrderExchanges(
filters?: FilterableOrderProps,
config?: FindConfig<OrderExchangeDTO>,
sharedContext?: Context
): Promise<OrderExchangeDTO[]>
listAndCountOrderExchanges(
filters?: FilterableOrderProps,
config?: FindConfig<OrderExchangeDTO>,
sharedContext?: Context
): Promise<[OrderExchangeDTO[], number]>
/**
* This method creates {return type}(s)
*
@@ -1154,7 +1195,7 @@ export interface IOrderModuleService extends IModuleService {
*
* @param {string} orderId - The order's ID.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when {summary}
* @returns {Promise<OrderChangeReturn>} Resolves when {summary}
*
* @example
* ```typescript
@@ -1165,7 +1206,7 @@ export interface IOrderModuleService extends IModuleService {
confirmOrderChange(
orderChangeId: string,
sharedContext?: Context
): Promise<void>
): Promise<OrderChangeReturn>
/**
* This method Represents the completion of an asynchronous operation
@@ -1310,7 +1351,7 @@ export interface IOrderModuleService extends IModuleService {
*
* @param {string | string[]} orderId - The order's ID.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {(orderId: string | string[], sharedContext?: Context) => any} {summary}
* @returns {(orderId: string | string[], sharedContext?: Context) => Promise<OrderChangeReturn>} {summary}
*
* @example
* ```typescript
@@ -1318,7 +1359,10 @@ export interface IOrderModuleService extends IModuleService {
* ```
*
*/
applyPendingOrderActions(orderId: string | string[], sharedContext?: Context)
applyPendingOrderActions(
orderId: string | string[],
sharedContext?: Context
): Promise<OrderChangeReturn>
addOrderAction(
data: CreateOrderChangeActionDTO,
@@ -1532,7 +1576,7 @@ export interface IOrderModuleService extends IModuleService {
createReturn(
returnData: CreateOrderReturnDTO,
sharedContext?: Context
): Promise<any> // TODO: ReturnDTO
): Promise<ReturnDTO>
/*
cancelReturn(
@@ -1544,5 +1588,15 @@ export interface IOrderModuleService extends IModuleService {
receiveReturn(
returnData: ReceiveOrderReturnDTO,
sharedContext?: Context
): Promise<any> // TODO: ReturnDTO
): Promise<ReturnDTO>
createClaim(
claimData: CreateOrderClaimDTO,
sharedContext?: Context
): Promise<OrderClaimDTO>
createExchange(
exchangeData: CreateOrderExchangeDTO,
sharedContext?: Context
): Promise<OrderExchangeDTO>
}
+2 -3
View File
@@ -1,4 +1,3 @@
import { EntityManager } from "typeorm"
import { EventBusTypes } from "./bundles"
import { Message } from "./event-bus"
@@ -12,11 +11,11 @@ export type SharedContext = {
/**
* An instance of a transaction manager.
*/
transactionManager?: EntityManager
transactionManager?: any
/**
* An instance of an entity manager.
*/
manager?: EntityManager
manager?: any
}
export interface MessageAggregatorFormat {
@@ -1,9 +1,10 @@
import { BigNumberInput } from "../../totals"
interface CreateOrderReturnItem {
interface CreateReturnItem {
id: string
quantity: BigNumberInput
internal_note?: string
note?: string
reason_id?: string
metadata?: Record<string, any>
}
@@ -11,7 +12,7 @@ interface CreateOrderReturnItem {
export interface CreateOrderReturnWorkflowInput {
order_id: string
created_by?: string // The id of the authenticated user
items: CreateOrderReturnItem[]
items: CreateReturnItem[]
return_shipping: {
option_id: string
price?: number
@@ -1,3 +1,4 @@
import { isDefined } from "./is-defined"
import { isObject } from "./is-object"
export function pickValueFromObject(
@@ -5,32 +6,28 @@ export function pickValueFromObject(
object: Record<any, any>
): any {
const segments = path.split(".")
let result: any = undefined
let result: any = object
for (const segment of segments) {
const segmentsLeft = [...segments].splice(1, segments.length - 1)
const segmentOutput = object[segment]
for (let i = 0; i < segments.length; i++) {
const segment = segments[i]
result = result[segment]
if (segmentsLeft.length === 0) {
result = segmentOutput
break
if (!isDefined(result)) {
return
}
if (isObject(segmentOutput)) {
result = pickValueFromObject(segmentsLeft.join("."), segmentOutput)
break
if (i === segments.length - 1) {
return result
}
if (Array.isArray(segmentOutput)) {
result = segmentOutput
.map((segmentOutput_) =>
pickValueFromObject(segmentsLeft.join("."), segmentOutput_)
)
.flat()
break
if (Array.isArray(result)) {
const subPath = segments.slice(i + 1).join(".")
return result.map((item) => pickValueFromObject(subPath, item)).flat()
}
result = segmentOutput
if (!isObject(result)) {
return result
}
}
return result