feat: Add product export endpoint and a dummy workflow (#8178)
This commit is contained in:
1 parent
1a472733ae
commit
8d083d6d0f
11 files changed
+469
-457
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { WorkflowTypes } from "@medusajs/types"
|
||||
|
||||
export const exportProductsWorkflowId = "export-products"
|
||||
export const exportProductsWorkflow = createWorkflow(
|
||||
exportProductsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<WorkflowTypes.ProductWorkflow.ExportProductsDTO>
|
||||
): WorkflowData<void> => {
|
||||
const products = useRemoteQueryStep({
|
||||
entry_point: "product",
|
||||
fields: input.select,
|
||||
variables: input.filter,
|
||||
list: true,
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -20,3 +20,4 @@ export * from "./update-product-types"
|
||||
export * from "./update-product-tags"
|
||||
export * from "./update-product-variants"
|
||||
export * from "./update-products"
|
||||
export * from "./export-products"
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BatchMethodRequest } from "../../../common"
|
||||
import { ProductStatus } from "../common"
|
||||
|
||||
export interface AdminExportProductRequest {}
|
||||
export interface AdminBatchProductRequest
|
||||
extends BatchMethodRequest<AdminCreateProduct, AdminUpdateProduct> {}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ export type AdminProductVariantListResponse = PaginatedResponse<{
|
||||
export interface AdminProductVariantDeleteResponse
|
||||
extends DeleteResponse<"variant", AdminProduct> {}
|
||||
|
||||
export interface AdminExportProductResponse {
|
||||
workflow_id: string
|
||||
}
|
||||
|
||||
export interface AdminBatchProductVariantResponse
|
||||
extends BatchMethodResponse<AdminProductVariant> {}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { FilterableProductProps } from "../../product"
|
||||
|
||||
export interface ExportProductsDTO {
|
||||
select: string[]
|
||||
filter?: FilterableProductProps
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * from "./create-product-variants"
|
||||
export * from "./create-products"
|
||||
export * from "./update-product-variants"
|
||||
export * from "./update-products"
|
||||
export * from "./export-products"
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../types/routing"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { remapKeysForProduct } from "../helpers"
|
||||
import { exportProductsWorkflow } from "@medusajs/core-flows"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<HttpTypes.AdminExportProductRequest>,
|
||||
res: MedusaResponse<HttpTypes.AdminExportProductResponse>
|
||||
) => {
|
||||
const selectFields = remapKeysForProduct(req.remoteQueryConfig.fields ?? [])
|
||||
const input = { select: selectFields, filter: req.filterableFields }
|
||||
|
||||
const { transaction } = await exportProductsWorkflow(req.scope).run({
|
||||
input,
|
||||
})
|
||||
|
||||
res.status(202).json({ workflow_id: transaction.transactionId })
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
AdminCreateProductOption,
|
||||
AdminCreateProductVariant,
|
||||
AdminCreateVariantInventoryItem,
|
||||
AdminExportProduct,
|
||||
AdminGetProductOptionParams,
|
||||
AdminGetProductOptionsParams,
|
||||
AdminGetProductParams,
|
||||
@@ -69,12 +70,23 @@ export const adminProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/products/export",
|
||||
middlewares: [
|
||||
validateAndTransformBody(AdminExportProduct),
|
||||
validateAndTransformQuery(
|
||||
AdminGetProductsParams,
|
||||
QueryConfig.listProductQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/products/:id",
|
||||
middlewares: [
|
||||
unlessPath(
|
||||
/.*\/products\/batch/,
|
||||
/.*\/products\/(batch|export)/,
|
||||
validateAndTransformQuery(
|
||||
AdminGetProductParams,
|
||||
QueryConfig.retrieveProductQueryConfig
|
||||
@@ -87,11 +99,11 @@ export const adminProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
matcher: "/admin/products/:id",
|
||||
middlewares: [
|
||||
unlessPath(
|
||||
/.*\/products\/batch/,
|
||||
/.*\/products\/(batch|export)/,
|
||||
validateAndTransformBody(AdminUpdateProduct)
|
||||
),
|
||||
unlessPath(
|
||||
/.*\/products\/batch/,
|
||||
/.*\/products\/(batch|export)/,
|
||||
validateAndTransformQuery(
|
||||
AdminGetProductParams,
|
||||
QueryConfig.retrieveProductQueryConfig
|
||||
@@ -104,7 +116,7 @@ export const adminProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
matcher: "/admin/products/:id",
|
||||
middlewares: [
|
||||
unlessPath(
|
||||
/.*\/products\/batch/,
|
||||
/.*\/products\/(batch|export)/,
|
||||
validateAndTransformQuery(
|
||||
AdminGetProductParams,
|
||||
QueryConfig.retrieveProductQueryConfig
|
||||
|
||||
@@ -268,6 +268,9 @@ export const AdminBatchUpdateProduct = AdminUpdateProduct.extend({
|
||||
id: z.string(),
|
||||
})
|
||||
|
||||
export type AdminExportProductType = z.infer<typeof AdminExportProduct>
|
||||
export const AdminExportProduct = z.object({})
|
||||
|
||||
// TODO: Handle in create and update product once ready
|
||||
// @IsOptional()
|
||||
// @Type(() => ProductProductCategoryReq)
|
||||
|
||||
Reference in new issue
Block a user