diff --git a/integration-tests/http/__tests__/claims/claims.spec.ts b/integration-tests/http/__tests__/claims/claims.spec.ts index 3771881e9a..022aa39ac0 100644 --- a/integration-tests/http/__tests__/claims/claims.spec.ts +++ b/integration-tests/http/__tests__/claims/claims.spec.ts @@ -1048,6 +1048,8 @@ medusaIntegrationTestRunner({ ) ).data.claim + expect(baseClaim.created_by).toEqual(expect.any(String)) + await api.post( `/admin/claims/${baseClaim.id}/inbound/items`, { diff --git a/integration-tests/http/__tests__/exchanges/exchanges.spec.ts b/integration-tests/http/__tests__/exchanges/exchanges.spec.ts index 421aeac433..72663e0688 100644 --- a/integration-tests/http/__tests__/exchanges/exchanges.spec.ts +++ b/integration-tests/http/__tests__/exchanges/exchanges.spec.ts @@ -392,6 +392,8 @@ medusaIntegrationTestRunner({ adminHeaders ) + expect(result.data.exchange.created_by).toEqual(expect.any(String)) + const exchangeId = result.data.exchange.id let r2 = await api.post( diff --git a/integration-tests/http/__tests__/returns/returns.spec.ts b/integration-tests/http/__tests__/returns/returns.spec.ts index a2a2ef5610..ff21806b87 100644 --- a/integration-tests/http/__tests__/returns/returns.spec.ts +++ b/integration-tests/http/__tests__/returns/returns.spec.ts @@ -311,6 +311,8 @@ medusaIntegrationTestRunner({ adminHeaders ) + expect(result.data.return.created_by).toEqual(expect.any(String)) + let r2 = await api.post( "/admin/returns", { diff --git a/integration-tests/modules/__tests__/fulfillment/index.spec.ts b/integration-tests/modules/__tests__/fulfillment/index.spec.ts index 03e2428e90..70a657f78f 100644 --- a/integration-tests/modules/__tests__/fulfillment/index.spec.ts +++ b/integration-tests/modules/__tests__/fulfillment/index.spec.ts @@ -156,6 +156,7 @@ medusaIntegrationTestRunner({ shipped_at: null, delivered_at: null, canceled_at: null, + created_by: expect.any(String), provider_id: "manual_test-provider", delivery_address: expect.objectContaining({ address_1: expect.any(String), @@ -240,6 +241,7 @@ medusaIntegrationTestRunner({ expect.objectContaining({ id: fulfillment.id, shipped_at: expect.any(String), + marked_shipped_by: expect.any(String), labels: [ expect.objectContaining({ id: expect.any(String), diff --git a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts index 3ceda84272..1cab64ef18 100644 --- a/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts +++ b/packages/core/core-flows/src/order/workflows/claim/begin-order-claim.ts @@ -45,6 +45,7 @@ export const beginClaimOrderWorkflow = createWorkflow( type: input.type, order_id: input.order_id, metadata: input.metadata, + created_by: input.created_by, }, ]) diff --git a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts index 7819bdc222..443675fc65 100644 --- a/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts +++ b/packages/core/core-flows/src/order/workflows/exchange/begin-order-exchange.ts @@ -44,6 +44,7 @@ export const beginExchangeOrderWorkflow = createWorkflow( { order_id: input.order_id, metadata: input.metadata, + created_by: input.created_by, }, ]) diff --git a/packages/core/core-flows/src/order/workflows/return/begin-return.ts b/packages/core/core-flows/src/order/workflows/return/begin-return.ts index 94d0bbcfba..5bfea496d6 100644 --- a/packages/core/core-flows/src/order/workflows/return/begin-return.ts +++ b/packages/core/core-flows/src/order/workflows/return/begin-return.ts @@ -44,6 +44,7 @@ export const beginReturnOrderWorkflow = createWorkflow( order_id: input.order_id, location_id: input.location_id, metadata: input.metadata, + created_by: input.created_by, }, ]) diff --git a/packages/core/types/src/fulfillment/common/fulfillment.ts b/packages/core/types/src/fulfillment/common/fulfillment.ts index 81099c84ef..48670f00fd 100644 --- a/packages/core/types/src/fulfillment/common/fulfillment.ts +++ b/packages/core/types/src/fulfillment/common/fulfillment.ts @@ -1,9 +1,9 @@ -import { ShippingOptionDTO } from "./shipping-option" -import { FulfillmentProviderDTO } from "./fulfillment-provider" +import { BaseFilterable, OperatorMap } from "../../dal" import { FulfillmentAddressDTO } from "./address" import { FulfillmentItemDTO } from "./fulfillment-item" import { FulfillmentLabelDTO } from "./fulfillment-label" -import { BaseFilterable, OperatorMap } from "../../dal" +import { FulfillmentProviderDTO } from "./fulfillment-provider" +import { ShippingOptionDTO } from "./shipping-option" /** * The fulfillment details. @@ -39,6 +39,16 @@ export interface FulfillmentDTO { */ canceled_at: Date | null + /** + * The id of the user that marked fulfillment as shipped + */ + marked_shipped_by?: string | null + + /** + * The id of the user that created the fulfillment + */ + created_by?: string | null + /** * The data necessary for the fulfillment provider to process * the fulfillment. diff --git a/packages/core/types/src/fulfillment/mutations/fulfillment.ts b/packages/core/types/src/fulfillment/mutations/fulfillment.ts index 843fe3acd2..ceed876c7e 100644 --- a/packages/core/types/src/fulfillment/mutations/fulfillment.ts +++ b/packages/core/types/src/fulfillment/mutations/fulfillment.ts @@ -22,6 +22,11 @@ export interface CreateFulfillmentDTO { */ shipped_at?: Date | null + /** + * The id of the user that created the fulfillment + */ + created_by?: string | null + /** * The date the fulfillment was delivered. */ diff --git a/packages/core/types/src/order/common.ts b/packages/core/types/src/order/common.ts index a32b130da7..e091439d96 100644 --- a/packages/core/types/src/order/common.ts +++ b/packages/core/types/src/order/common.ts @@ -1584,6 +1584,11 @@ export interface OrderClaimDTO * The refund amount of the claim. */ refund_amount?: BigNumberValue + + /** + * The id of the user that creates the order claim + */ + created_by?: string | null } /** @@ -1630,6 +1635,11 @@ export interface OrderExchangeDTO * The associated return's ID. */ return_id?: string + + /** + * The id of the user that creates the order exchange + */ + created_by?: string | null } /** diff --git a/packages/core/types/src/order/mutations.ts b/packages/core/types/src/order/mutations.ts index 9040cbcfd5..5f49bb84a9 100644 --- a/packages/core/types/src/order/mutations.ts +++ b/packages/core/types/src/order/mutations.ts @@ -890,7 +890,7 @@ export interface CreateOrderChangeDTO { /** * The user that created the order change. */ - created_by?: string + created_by?: string | null /** * Holds custom data in key-value pairs. @@ -1537,6 +1537,11 @@ export interface CreateOrderReturnDTO extends BaseOrderBundledActionsDTO { * The associated exchange's ID. */ exchange_id?: string + + /** + * The id of the user that creates the fulfillment + */ + created_by?: string | null } /** @@ -1967,6 +1972,11 @@ export interface CreateOrderClaimDTO extends BaseOrderBundledActionsDTO { * on the claim. */ no_notification?: boolean + + /** + * The id of the user that creates the order claim + */ + created_by?: string | null } export interface CancelOrderClaimDTO extends BaseOrderBundledActionsDTO { @@ -2012,6 +2022,11 @@ export interface CreateOrderExchangeDTO extends BaseOrderBundledActionsDTO { * updates on the exchange. */ no_notification?: boolean + + /** + * The id of the user that creates the order exchange + */ + created_by?: string | null } export interface CancelOrderExchangeDTO extends BaseOrderBundledActionsDTO { diff --git a/packages/core/types/src/workflow/fulfillment/create-fulfillment.ts b/packages/core/types/src/workflow/fulfillment/create-fulfillment.ts index a186c9e8d3..70c3e91f32 100644 --- a/packages/core/types/src/workflow/fulfillment/create-fulfillment.ts +++ b/packages/core/types/src/workflow/fulfillment/create-fulfillment.ts @@ -131,6 +131,11 @@ export type CreateFulfillmentWorkflowInput = { */ shipped_at?: Date | null + /** + * The id of the user that creates the fulfillment + */ + created_by?: string | null + /** * The date the fulfillment was delivered. */ diff --git a/packages/core/types/src/workflow/fulfillment/create-shipment.ts b/packages/core/types/src/workflow/fulfillment/create-shipment.ts index 9389c58b1a..7baf825431 100644 --- a/packages/core/types/src/workflow/fulfillment/create-shipment.ts +++ b/packages/core/types/src/workflow/fulfillment/create-shipment.ts @@ -13,4 +13,9 @@ export interface CreateShipmentWorkflowInput { * The labels associated with the fulfillment. */ labels: CreateFulfillmentLabelWorkflowDTO[] + + /** + * The id of the user that marked fulfillment as shipped + */ + marked_shipped_by?: string | null } diff --git a/packages/core/types/src/workflow/fulfillment/update-fulfillment.ts b/packages/core/types/src/workflow/fulfillment/update-fulfillment.ts index 1a3eb09047..e06848e721 100644 --- a/packages/core/types/src/workflow/fulfillment/update-fulfillment.ts +++ b/packages/core/types/src/workflow/fulfillment/update-fulfillment.ts @@ -22,6 +22,16 @@ export interface UpdateFulfillmentWorkflowInput { */ shipped_at?: Date | null + /** + * The id of the user that marked fulfillment as shipped + */ + marked_shipped_by?: string | null + + /** + * The id of the user that created the fulfillment + */ + created_by?: string | null + /** * The date the fulfillment was delivered. */ diff --git a/packages/core/types/src/workflow/order/begin-claim-order.ts b/packages/core/types/src/workflow/order/begin-claim-order.ts index c2b0c37326..3246c6bb78 100644 --- a/packages/core/types/src/workflow/order/begin-claim-order.ts +++ b/packages/core/types/src/workflow/order/begin-claim-order.ts @@ -3,7 +3,10 @@ import { OrderClaimType } from "../../order/mutations" export interface BeginOrderClaimWorkflowInput { type: OrderClaimType order_id: string - created_by?: string + /** + * The id of the user that creates the order claim + */ + created_by?: string | null internal_note?: string description?: string metadata?: Record | null diff --git a/packages/core/types/src/workflow/order/begin-exchange-order.ts b/packages/core/types/src/workflow/order/begin-exchange-order.ts index aa3e121a18..d449a51532 100644 --- a/packages/core/types/src/workflow/order/begin-exchange-order.ts +++ b/packages/core/types/src/workflow/order/begin-exchange-order.ts @@ -1,6 +1,9 @@ export interface BeginOrderExchangeWorkflowInput { order_id: string - created_by?: string + /** + * The id of the user that creates the order exchange + */ + created_by?: string | null internal_note?: string description?: string metadata?: Record | null diff --git a/packages/core/types/src/workflow/order/begin-return-order.ts b/packages/core/types/src/workflow/order/begin-return-order.ts index adaaaf07a6..918ab0497b 100644 --- a/packages/core/types/src/workflow/order/begin-return-order.ts +++ b/packages/core/types/src/workflow/order/begin-return-order.ts @@ -1,7 +1,10 @@ export interface BeginOrderReturnWorkflowInput { order_id: string location_id?: string - created_by?: string + /** + * The id of the user that creates the return + */ + created_by?: string | null internal_note?: string description?: string metadata?: Record | null diff --git a/packages/medusa/src/api/admin/claims/query-config.ts b/packages/medusa/src/api/admin/claims/query-config.ts index 4d5114ac51..4da4ce2aea 100644 --- a/packages/medusa/src/api/admin/claims/query-config.ts +++ b/packages/medusa/src/api/admin/claims/query-config.ts @@ -6,6 +6,7 @@ export const defaultAdminClaimFields = [ "display_id", "order_version", "refund_amount", + "created_by", "created_at", "updated_at", "canceled_at", diff --git a/packages/medusa/src/api/admin/claims/route.ts b/packages/medusa/src/api/admin/claims/route.ts index fba9dfa35f..be793a10fc 100644 --- a/packages/medusa/src/api/admin/claims/route.ts +++ b/packages/medusa/src/api/admin/claims/route.ts @@ -1,4 +1,5 @@ import { beginClaimOrderWorkflow } from "@medusajs/core-flows" +import { HttpTypes } from "@medusajs/types" import { ContainerRegistrationKeys, ModuleRegistrationName, @@ -10,7 +11,6 @@ import { MedusaResponse, } from "../../../types/routing" import { AdminPostOrderClaimsReqSchemaType } from "./validators" -import { HttpTypes } from "@medusajs/types" export const GET = async ( req: AuthenticatedMedusaRequest, @@ -43,7 +43,11 @@ export const POST = async ( req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { - const input = req.validatedBody as AdminPostOrderClaimsReqSchemaType + const input = { + ...req.validatedBody, + created_by: req.auth_context.actor_id, + } + const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) const orderModuleService = req.scope.resolve(ModuleRegistrationName.ORDER) diff --git a/packages/medusa/src/api/admin/exchanges/query-config.ts b/packages/medusa/src/api/admin/exchanges/query-config.ts index cc023880e8..37668bcb22 100644 --- a/packages/medusa/src/api/admin/exchanges/query-config.ts +++ b/packages/medusa/src/api/admin/exchanges/query-config.ts @@ -5,6 +5,7 @@ export const defaultAdminExchangeFields = [ "return_id", "display_id", "order_version", + "created_by", "created_at", "updated_at", "canceled_at", diff --git a/packages/medusa/src/api/admin/exchanges/route.ts b/packages/medusa/src/api/admin/exchanges/route.ts index f43800541e..6646b68de9 100644 --- a/packages/medusa/src/api/admin/exchanges/route.ts +++ b/packages/medusa/src/api/admin/exchanges/route.ts @@ -1,4 +1,5 @@ import { beginExchangeOrderWorkflow } from "@medusajs/core-flows" +import { HttpTypes } from "@medusajs/types" import { ContainerRegistrationKeys, ModuleRegistrationName, @@ -10,7 +11,6 @@ import { MedusaResponse, } from "../../../types/routing" import { AdminPostOrderExchangesReqSchemaType } from "./validators" -import { HttpTypes } from "@medusajs/types" export const GET = async ( req: AuthenticatedMedusaRequest, @@ -43,7 +43,11 @@ export const POST = async ( req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { - const input = req.validatedBody as AdminPostOrderExchangesReqSchemaType + const input = { + ...req.validatedBody, + created_by: req.auth_context.actor_id, + } + const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) const orderModuleService = req.scope.resolve(ModuleRegistrationName.ORDER) diff --git a/packages/medusa/src/api/admin/fulfillments/[id]/shipment/route.ts b/packages/medusa/src/api/admin/fulfillments/[id]/shipment/route.ts index 3b070006a2..c639da2117 100644 --- a/packages/medusa/src/api/admin/fulfillments/[id]/shipment/route.ts +++ b/packages/medusa/src/api/admin/fulfillments/[id]/shipment/route.ts @@ -1,11 +1,11 @@ import { createShipmentWorkflow } from "@medusajs/core-flows" +import { HttpTypes } from "@medusajs/types" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../../../types/routing" import { refetchFulfillment } from "../../helpers" import { AdminCreateShipmentType } from "../../validators" -import { HttpTypes } from "@medusajs/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -14,7 +14,11 @@ export const POST = async ( const { id } = req.params await createShipmentWorkflow(req.scope).run({ - input: { id, ...req.validatedBody }, + input: { + ...req.validatedBody, + id, + marked_shipped_by: req.auth_context.actor_id, + }, }) const fulfillment = await refetchFulfillment( diff --git a/packages/medusa/src/api/admin/fulfillments/query-config.ts b/packages/medusa/src/api/admin/fulfillments/query-config.ts index 4fb6232135..4032d5214c 100644 --- a/packages/medusa/src/api/admin/fulfillments/query-config.ts +++ b/packages/medusa/src/api/admin/fulfillments/query-config.ts @@ -3,6 +3,8 @@ export const defaultAdminFulfillmentsFields = [ "location_id", "packed_at", "shipped_at", + "marked_shipped_by", + "created_by", "delivered_at", "canceled_at", "data", diff --git a/packages/medusa/src/api/admin/fulfillments/route.ts b/packages/medusa/src/api/admin/fulfillments/route.ts index e05babc12a..f23e6c959d 100644 --- a/packages/medusa/src/api/admin/fulfillments/route.ts +++ b/packages/medusa/src/api/admin/fulfillments/route.ts @@ -1,11 +1,11 @@ import { createFulfillmentWorkflow } from "@medusajs/core-flows" +import { HttpTypes } from "@medusajs/types" import { AuthenticatedMedusaRequest, MedusaResponse, } from "../../../types/routing" import { refetchFulfillment } from "./helpers" import { AdminCreateFulfillmentType } from "./validators" -import { HttpTypes } from "@medusajs/types" export const POST = async ( req: AuthenticatedMedusaRequest, @@ -14,7 +14,10 @@ export const POST = async ( const { result: fullfillment } = await createFulfillmentWorkflow( req.scope ).run({ - input: req.validatedBody, + input: { + ...req.validatedBody, + created_by: req.auth_context.actor_id, + }, }) const fulfillment = await refetchFulfillment( diff --git a/packages/medusa/src/api/admin/returns/query-config.ts b/packages/medusa/src/api/admin/returns/query-config.ts index ef67cbe938..b723a5a2fe 100644 --- a/packages/medusa/src/api/admin/returns/query-config.ts +++ b/packages/medusa/src/api/admin/returns/query-config.ts @@ -10,6 +10,7 @@ export const defaultAdminReturnFields = [ "metadata", "no_notification", "refund_amount", + "created_by", "created_at", "updated_at", "canceled_at", diff --git a/packages/medusa/src/api/admin/returns/route.ts b/packages/medusa/src/api/admin/returns/route.ts index 34eb1b62c5..8fed2d27c3 100644 --- a/packages/medusa/src/api/admin/returns/route.ts +++ b/packages/medusa/src/api/admin/returns/route.ts @@ -1,4 +1,5 @@ import { beginReturnOrderWorkflow } from "@medusajs/core-flows" +import { HttpTypes } from "@medusajs/types" import { ContainerRegistrationKeys, ModuleRegistrationName, @@ -10,7 +11,6 @@ import { MedusaResponse, } from "../../../types/routing" import { AdminPostReturnsReqSchemaType } from "./validators" -import { HttpTypes } from "@medusajs/types" export const GET = async ( req: AuthenticatedMedusaRequest, @@ -43,7 +43,11 @@ export const POST = async ( req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { - const input = req.validatedBody as AdminPostReturnsReqSchemaType + const input = { + ...req.validatedBody, + created_by: req.auth_context.actor_id, + } + const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) const orderModuleService = req.scope.resolve(ModuleRegistrationName.ORDER)