feat(medusa): List batch jobs + Introduce composable handler pattern (#1541)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user