feat(medusa, medusa-js, medusa-react): Implement Sales Channel retrieval (#1793)

This commit is contained in:
Adrien de Peretti
2022-07-06 12:17:26 +02:00
committed by GitHub
parent e115518dda
commit 263a661031
26 changed files with 511 additions and 34 deletions
+1
View File
@@ -15,3 +15,4 @@ export * from "./simple-shipping-method-factory"
export * from "./simple-product-type-tax-rate-factory"
export * from "./simple-price-list-factory"
export * from "./simple-batch-job-factory"
export * from "./simple-sales-channel-factory"
@@ -0,0 +1,31 @@
import { Connection } from "typeorm"
import faker from "faker"
import { SalesChannel } from "@medusajs/medusa"
export type SalesChannelFactoryData = {
name?: string
description?: string
is_disabled?: boolean
}
export const simpleSalesChannelFactory = async (
connection: Connection,
data: SalesChannelFactoryData = {},
seed?: number
): Promise<SalesChannel> => {
if (typeof seed !== "undefined") {
faker.seed(seed)
}
const manager = connection.manager
const salesChannel = manager.create(SalesChannel, {
id: `simple-id-${Math.random() * 1000}`,
name: data.name || faker.name.firstName(),
description: data.description || faker.name.lastName(),
is_disabled:
typeof data.is_disabled !== undefined ? data.is_disabled : false,
})
return await manager.save(salesChannel)
}