feat(medusa): List batch jobs + Introduce composable handler pattern (#1541)

This commit is contained in:
Adrien de Peretti
2022-05-20 10:22:42 +02:00
committed by GitHub
parent f0ecef6b9a
commit 4489b75f5a
15 changed files with 521 additions and 10 deletions
+1
View File
@@ -1,4 +1,5 @@
export * from "./simple-payment-factory"
export * from "./simple-batch-job-factory"
export * from "./simple-order-factory"
export * from "./simple-cart-factory"
export * from "./simple-region-factory"
@@ -0,0 +1,27 @@
import { Connection } from "typeorm"
import { BatchJob, BatchJobStatus } from "@medusajs/medusa"
export type BatchJobFactoryData = {
id?: string
type?: string
status?: BatchJobStatus
created_by?: string
context?: Record<string, unknown>
}
export const simpleBatchJobFactory = async (
connection: Connection,
data: BatchJobFactoryData = {}
): Promise<BatchJob> => {
const manager = connection.manager
const job = manager.create(BatchJob, {
id: data.id,
status: data.status ?? BatchJobStatus.CREATED,
type: data.type ?? "test-job",
created_by: data.created_by ?? null,
context: data.context ?? {},
})
return await manager.save(job)
}