feat(medusa): Implement premises of order edit retrieval (#2183)
**What** - Implements the admin/store retrieval end point - Service implementation of the retrieve method - Service implementation of the computeLineItems method which aggregates the right line item based on the changes that are made - client - medusa-js api - medusa-react queries hooks **Tests** - Unit tests of the retrieval end points - Unit tests of the service retrieve method and computeLineItems - Integration tests for admin/store - client - medusa-js tests - medusa-react hooks tests FIXES CORE-492
This commit is contained in:
committed by
GitHub
parent
3efeb6b84f
commit
f863d28b9a
@@ -0,0 +1,52 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { OrderFactoryData, simpleOrderFactory } from "./simple-order-factory"
|
||||
import { OrderEdit } from "@medusajs/medusa"
|
||||
|
||||
export type OrderEditFactoryData = {
|
||||
id?: string
|
||||
order?: OrderFactoryData
|
||||
order_id?: string
|
||||
internal_note?: string
|
||||
declined_reason?: string
|
||||
confirmed_at?: Date | string
|
||||
confirmed_by?: string
|
||||
created_at?: Date | string
|
||||
created_by?: string
|
||||
requested_at?: Date | string
|
||||
requested_by?: string
|
||||
canceled_at?: Date | string
|
||||
canceled_by?: string
|
||||
declined_at?: Date | string
|
||||
declined_by?: string
|
||||
}
|
||||
|
||||
export const simpleOrderEditFactory = async (
|
||||
connection: Connection,
|
||||
data: OrderEditFactoryData = {}
|
||||
): Promise<OrderEdit> => {
|
||||
const manager = connection.manager
|
||||
|
||||
if (!data.order_id) {
|
||||
const order = await simpleOrderFactory(connection, data.order)
|
||||
data.order_id = order.id
|
||||
}
|
||||
|
||||
const orderEdit = manager.create<OrderEdit>(OrderEdit, {
|
||||
id: data.id,
|
||||
order_id: data.order_id,
|
||||
internal_note: data.internal_note,
|
||||
declined_reason: data.declined_reason,
|
||||
declined_at: data.declined_at,
|
||||
declined_by: data.declined_by,
|
||||
canceled_at: data.canceled_at,
|
||||
canceled_by: data.canceled_by,
|
||||
requested_at: data.requested_at,
|
||||
requested_by: data.requested_by,
|
||||
created_at: data.created_at,
|
||||
created_by: data.created_by,
|
||||
confirmed_at: data.confirmed_at,
|
||||
confirmed_by: data.confirmed_by,
|
||||
})
|
||||
|
||||
return await manager.save<OrderEdit>(orderEdit)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
OrderEdit,
|
||||
OrderEditItemChangeType,
|
||||
OrderItemChange,
|
||||
} from "@medusajs/medusa"
|
||||
import { Connection } from "typeorm"
|
||||
|
||||
type OrderItemChangeData = {
|
||||
id: string
|
||||
type: OrderEditItemChangeType
|
||||
order_edit_id: string
|
||||
original_line_item_id?: string
|
||||
line_item_id?: string
|
||||
}
|
||||
|
||||
export const simpleOrderItemChangeFactory = async (
|
||||
connection: Connection,
|
||||
data: OrderItemChangeData
|
||||
) => {
|
||||
const manager = connection.manager
|
||||
const change = manager.create<OrderItemChange>(OrderItemChange, {
|
||||
id: data.id,
|
||||
type: data.type,
|
||||
order_edit_id: data.order_edit_id,
|
||||
line_item_id: data.line_item_id,
|
||||
original_line_item_id: data.original_line_item_id,
|
||||
})
|
||||
|
||||
return await manager.save<OrderItemChange>(change)
|
||||
}
|
||||
Reference in New Issue
Block a user