Skip to content

Commit

Permalink
core flows
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues committed Jan 8, 2025
1 parent a708664 commit 5dd6b53
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 215 deletions.
4 changes: 2 additions & 2 deletions integration-tests/http/__tests__/exchanges/exchanges.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
ContainerRegistrationKeys,
Modules,
RuleOperator,
} from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
import {
adminHeaders,
createAdminUser,
} from "../../../helpers/create-admin-user"
import { setupTaxStructure } from "../../../modules/__tests__/fixtures/tax"

jest.setTimeout(30000)
jest.setTimeout(300000)

medusaIntegrationTestRunner({
testSuite: ({ dbConnection, getContainer, api }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const updateOrderClaimsStep = createStep(
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
objectFields: ["metadata"],
})
const dataBeforeUpdate = await service.listOrderClaims(
const dataBeforeUpdate = (await service.listOrderClaims(
{ id: data.map((d) => d.id) },
{ relations, select: selects }
)
)) as UpdateOrderClaimDTO[]

const updated = await service.updateOrderClaims(
data.map((dt) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const updateOrderExchangesStep = createStep(
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
objectFields: ["metadata"],
})
const dataBeforeUpdate = await service.listOrderExchanges(
const dataBeforeUpdate = (await service.listOrderExchanges(
{ id: data.map((d) => d.id) },
{ relations, select: selects }
)
)) as UpdateOrderExchangeDTO[]

const updated = await service.updateOrderExchanges(
data.map((dt) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/core-flows/src/order/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from "./exchange/create-exchange-items-from-actions"
export * from "./exchange/delete-exchanges"
export * from "./preview-order-change"
export * from "./register-fulfillment"
export * from "./register-order-changes"
export * from "./register-shipment"
export * from "./return/cancel-return"
export * from "./return/create-complete-return"
Expand All @@ -32,7 +33,5 @@ export * from "./return/update-returns"
export * from "./set-tax-lines-for-items"
export * from "./update-order-change-actions"
export * from "./update-order-changes"
export * from "./update-order-exchanges"
export * from "./update-shipping-methods"
export * from "./update-orders"
export * from "./register-order-changes"
export * from "./update-shipping-methods"
57 changes: 0 additions & 57 deletions packages/core/core-flows/src/order/steps/update-order-exchanges.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const beginClaimOrderWorkflow = createWorkflow(
return {
change_type: "claim" as const,
order_id: input.order_id,
claim: created[0].id,
claim_id: created[0].id,
created_by: input.created_by,
description: input.description,
internal_note: input.internal_note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
})

const orderReturn: ReturnDTO = transform(
{ createdReturn, existingOrderReturn },
({ createdReturn, existingOrderReturn }) => {
{ createdReturn, existingOrderReturn, orderClaim },
({ createdReturn, existingOrderReturn, orderClaim }) => {
return existingOrderReturn ?? (createdReturn?.[0] as ReturnDTO)
}
)
Expand Down Expand Up @@ -123,14 +123,17 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
name: "order-change-query",
})

when({ createdReturn }, ({ createdReturn }) => {
return !!createdReturn?.length
}).then(() => {
when(
{ createdReturn, orderClaim, orderChange },
({ createdReturn, orderClaim, orderChange }) => {
return !!createdReturn?.length
}
).then(() => {
updateOrderChangesStep([
{
id: orderChange.id,
return: orderReturn.id,
} as any,
return_id: createdReturn?.[0]?.id,
},
])
})

Expand All @@ -145,16 +148,10 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
when({ orderClaim }, ({ orderClaim }) => {
return !orderClaim.return_id
}).then(() => {
const createdReturnId = transform(
{ createdReturn },
({ createdReturn }) => {
return createdReturn?.[0]!.id
}
)
updateOrderClaimsStep([
{
id: orderClaim.id,
return_id: createdReturnId,
return: createdReturn?.[0]!.id,
},
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export const confirmClaimRequestWorkflow = createWorkflow(
fields: [
"id",
"status",
"claim_id",
"return_id",
"actions.id",
"actions.claim_id",
"actions.return_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const beginExchangeOrderWorkflow = createWorkflow(
return {
change_type: "exchange" as const,
order_id: input.order_id,
exchange: created[0].id,
exchange_id: created[0].id,
created_by: input.created_by,
description: input.description,
internal_note: input.internal_note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
updateOrderChangesStep([
{
id: orderChange.id,
return: createdReturn?.[0]?.id,
} as any,
return_id: createdReturn?.[0]?.id,
},
])
})

Expand All @@ -147,16 +147,10 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
when({ orderExchange }, ({ orderExchange }) => {
return !orderExchange.return_id
}).then(() => {
const createdReturnId = transform(
{ createdReturn },
({ createdReturn }) => {
return createdReturn?.[0]!.id
}
)
updateOrderExchangesStep([
{
id: orderExchange.id,
return_id: createdReturnId,
return: createdReturn?.[0]!.id,
},
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const beginReturnOrderWorkflow = createWorkflow(
return {
change_type: "return_request" as const,
order_id: input.order_id,
return: created[0].id,
return_id: created[0].id,
created_by: input.created_by,
description: input.description,
internal_note: input.internal_note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ export const removeItemReturnActionWorkflow = createWorkflow(

const updatedOrderChange: OrderChangeDTO = useRemoteQueryStep({
entry_point: "order_change",
fields: ["actions.action", "actions.return_id", "actions.id"],
fields: [
"actions.id",
"actions.action",
"actions.order_id",
"actions.return_id",
"actions.claim_id",
"actions.exchange_id",
"actions.reference",
"actions.reference_id",
"actions.order_change_id",
],
variables: {
filters: {
order_id: orderReturn.order_id,
Expand Down
15 changes: 15 additions & 0 deletions packages/core/types/src/order/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,21 @@ export interface FilterableOrderChangeProps
*/
order_id?: string | string[] | OperatorMap<string>

/**
* Filter the changes by their associated return's ID.
*/
return_id?: string | string[] | OperatorMap<string>

/**
* Filter the changes by their associated claim's ID.
*/
claim_id?: string | string[] | OperatorMap<string>

/**
* Filter the changes by their associated exchange's ID.
*/
exchange_id?: string | string[] | OperatorMap<string>

/**
* Filter the order changes by their status.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/src/order/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ export interface UpdateOrderClaimDTO {
* The associated return's ID, if the
* claim's {@link type} is `replace`.
*/
return_id?: string
return?: string

/**
* The type of the claim.
Expand Down Expand Up @@ -1777,7 +1777,7 @@ export interface UpdateOrderExchangeDTO {
/**
* The associated return's ID.
*/
return_id?: string
return?: string

/**
* Whether backorders are allowed on the exchange's items.
Expand Down
22 changes: 13 additions & 9 deletions packages/core/utils/src/dal/mikro-orm/big-number-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ export function MikroOrmBigNumberProperty(
} else {
let bigNumber: BigNumber

if (value instanceof BigNumber) {
bigNumber = value
} else if (this[rawColumnName]) {
const precision = this[rawColumnName].precision
bigNumber = new BigNumber(value, {
precision,
})
} else {
bigNumber = new BigNumber(value)
try {
if (value instanceof BigNumber) {
bigNumber = value
} else if (this[rawColumnName]) {
const precision = this[rawColumnName].precision
bigNumber = new BigNumber(value, {
precision,
})
} else {
bigNumber = new BigNumber(value)
}
} catch (e) {
throw new Error(`Cannot set value ${value} for ${columnName}.`)
}

const raw = bigNumber.raw!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export const POST = async (
},
})

const returnId = result.order_change.return_id
const queryObject = remoteQueryObjectFromString({
entryPoint: "return",
variables: {
id: claim.return_id,
id: returnId,
},
fields: defaultAdminDetailsReturnFields,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export const POST = async (
},
})

const returnId = result.order_change.return_id
const queryObject = remoteQueryObjectFromString({
entryPoint: "return",
variables: {
id: claim.return_id,
id: returnId,
},
fields: defaultAdminDetailsReturnFields,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import {
removeItemReturnActionWorkflow,
updateRequestItemReturnWorkflow,
} from "@medusajs/core-flows"
import { HttpTypes } from "@medusajs/framework/types"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/framework/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
refetchEntity,
} from "@medusajs/framework/http"
import { HttpTypes } from "@medusajs/framework/types"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/framework/utils"
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
import { AdminPostExchangesRequestItemsReturnActionReqSchemaType } from "../../../../validators"

Expand All @@ -29,7 +29,7 @@ export const POST = async (
variables: {
id,
},
fields: ["return_id"],
fields: ["id", "return_id"],
}),
{
throwIfKeyNotFound: true,
Expand Down
Loading

0 comments on commit 5dd6b53

Please sign in to comment.