chore(medusa): Typeorm upgrade to 0.3.11 (#3041)
This commit is contained in:
1 parent
8137061908
commit
121b42acfe
275 files changed
+4493
-4780
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { Address } from "@medusajs/medusa"
|
||||
|
||||
@@ -11,7 +11,7 @@ export type AddressFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleAddressFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: AddressFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Address> => {
|
||||
@@ -19,7 +19,7 @@ export const simpleAddressFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const address = manager.create(Address, {
|
||||
id: `simple-id-${Math.random() * 1000}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AnalyticsConfig } from "@medusajs/medusa"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
export type AnalyticsConfigData = {
|
||||
id?: string
|
||||
@@ -9,10 +9,10 @@ export type AnalyticsConfigData = {
|
||||
}
|
||||
|
||||
export const simpleAnalyticsConfigFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: AnalyticsConfigData = {}
|
||||
): Promise<AnalyticsConfig> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const job = manager.create<AnalyticsConfig>(AnalyticsConfig, {
|
||||
id: data.id ?? "test-analytics-config",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { BatchJob, BatchJobStatus } from "@medusajs/medusa"
|
||||
|
||||
export type BatchJobFactoryData = {
|
||||
@@ -12,10 +12,10 @@ export type BatchJobFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleBatchJobFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: BatchJobFactoryData = {}
|
||||
): Promise<BatchJob> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const job = manager.create<BatchJob>(BatchJob, {
|
||||
id: data.id,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Cart } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import {
|
||||
AddressFactoryData,
|
||||
simpleAddressFactory,
|
||||
@@ -32,7 +32,7 @@ export type CartFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleCartFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: CartFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Cart> => {
|
||||
@@ -40,37 +40,37 @@ export const simpleCartFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let regionId: string
|
||||
if (typeof data.region === "string") {
|
||||
regionId = data.region
|
||||
} else {
|
||||
const region = await simpleRegionFactory(connection, data.region)
|
||||
const region = await simpleRegionFactory(dataSource, data.region)
|
||||
regionId = region.id
|
||||
}
|
||||
|
||||
let customerId: string
|
||||
let customerId!: string
|
||||
if (typeof data.customer === "string") {
|
||||
customerId = data.customer
|
||||
} else {
|
||||
if (data?.customer?.email) {
|
||||
const customer = await simpleCustomerFactory(connection, data.customer)
|
||||
const customer = await simpleCustomerFactory(dataSource, data.customer)
|
||||
customerId = customer.id
|
||||
} else if (data.email) {
|
||||
const customer = await simpleCustomerFactory(connection, {
|
||||
const customer = await simpleCustomerFactory(dataSource, {
|
||||
email: data.email,
|
||||
})
|
||||
customerId = customer.id
|
||||
}
|
||||
}
|
||||
|
||||
const address = await simpleAddressFactory(connection, data.shipping_address)
|
||||
const address = await simpleAddressFactory(dataSource, data.shipping_address)
|
||||
|
||||
let sales_channel
|
||||
if (typeof data.sales_channel !== "undefined") {
|
||||
sales_channel = await simpleSalesChannelFactory(
|
||||
connection,
|
||||
dataSource,
|
||||
data.sales_channel
|
||||
)
|
||||
}
|
||||
@@ -90,12 +90,12 @@ export const simpleCartFactory = async (
|
||||
|
||||
const shippingMethods = data.shipping_methods || []
|
||||
for (const sm of shippingMethods) {
|
||||
await simpleShippingMethodFactory(connection, { ...sm, cart_id: id })
|
||||
await simpleShippingMethodFactory(dataSource, { ...sm, cart_id: id })
|
||||
}
|
||||
|
||||
const items = data.line_items || []
|
||||
for (const item of items) {
|
||||
await simpleLineItemFactory(connection, { ...item, cart_id: id })
|
||||
await simpleLineItemFactory(dataSource, { ...item, cart_id: id })
|
||||
}
|
||||
|
||||
return cart
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import {
|
||||
CustomShippingOption,
|
||||
} from "@medusajs/medusa"
|
||||
import { CustomShippingOption } from "@medusajs/medusa"
|
||||
|
||||
export type CustomShippingOptionFactoryData = {
|
||||
id?: string
|
||||
@@ -13,7 +11,7 @@ export type CustomShippingOptionFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleCustomShippingOptionFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: CustomShippingOptionFactoryData,
|
||||
seed?: number
|
||||
): Promise<CustomShippingOption> => {
|
||||
@@ -21,14 +19,14 @@ export const simpleCustomShippingOptionFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const customShippingOptionData = {
|
||||
id: data.id ?? `custon-simple-so-${Math.random() * 1000}`,
|
||||
price: typeof data.price !== "undefined" ? data.price : 500,
|
||||
cart_id: data.cart_id,
|
||||
shipping_option_id: data.shipping_option_id,
|
||||
metadata: data.metadata ?? {}
|
||||
metadata: data.metadata ?? {},
|
||||
}
|
||||
|
||||
const created = manager.create(CustomShippingOption, customShippingOptionData)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import faker from "faker"
|
||||
import { Customer } from "@medusajs/medusa"
|
||||
import { Connection } from "typeorm"
|
||||
import {
|
||||
CustomerGroupFactoryData,
|
||||
simpleCustomerGroupFactory,
|
||||
} from "./simple-customer-group-factory"
|
||||
import { DataSource } from "typeorm"
|
||||
import { Customer, CustomerGroup } from "@medusajs/medusa"
|
||||
import { CustomerGroupFactoryData, simpleCustomerGroupFactory, } from "./simple-customer-group-factory"
|
||||
|
||||
export type CustomerFactoryData = {
|
||||
id?: string
|
||||
@@ -18,7 +15,7 @@ export type CustomerFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleCustomerFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: CustomerFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Customer> => {
|
||||
@@ -26,7 +23,7 @@ export const simpleCustomerFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const customerId = data.id || `simple-customer-${Math.random() * 1000}`
|
||||
const c = manager.create(Customer, {
|
||||
@@ -49,9 +46,9 @@ export const simpleCustomerFactory = async (
|
||||
const customer = await manager.save(c)
|
||||
|
||||
if (data.groups) {
|
||||
const groups = []
|
||||
const groups: CustomerGroup[] = []
|
||||
for (const g of data.groups) {
|
||||
const created = await simpleCustomerGroupFactory(connection, g)
|
||||
const created = await simpleCustomerGroupFactory(dataSource, g)
|
||||
groups.push(created)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CustomerGroup } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
export type CustomerGroupFactoryData = {
|
||||
id?: string
|
||||
@@ -8,7 +8,7 @@ export type CustomerGroupFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleCustomerGroupFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: CustomerGroupFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<CustomerGroup> => {
|
||||
@@ -16,7 +16,7 @@ export const simpleCustomerGroupFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const customerGroupId =
|
||||
data.id || `simple-customer-group-${Math.random() * 1000}`
|
||||
|
||||
@@ -10,7 +10,7 @@ import { DiscountConditionProductTag } from "@medusajs/medusa/dist/models/discou
|
||||
import { DiscountConditionProductType } from "@medusajs/medusa/dist/models/discount-condition-product-type"
|
||||
import { DiscountConditionJoinTableForeignKey } from "@medusajs/medusa/dist/repositories/discount-condition"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
export type DiscountConditionFactoryData = {
|
||||
id?: string
|
||||
@@ -66,7 +66,7 @@ const getJoinTableResourceIdentifiers = (type: string) => {
|
||||
}
|
||||
|
||||
export const simpleDiscountConditionFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: DiscountConditionFactoryData,
|
||||
seed?: number
|
||||
): Promise<void> => {
|
||||
@@ -74,7 +74,7 @@ export const simpleDiscountConditionFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let resources = []
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ import {
|
||||
AllocationType,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
DiscountRuleType
|
||||
DiscountRuleType,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import {
|
||||
DiscountConditionFactoryData,
|
||||
simpleDiscountConditionFactory
|
||||
simpleDiscountConditionFactory,
|
||||
} from "./simple-discount-condition-factory"
|
||||
|
||||
export type DiscountRuleFactoryData = {
|
||||
@@ -29,7 +29,7 @@ export type DiscountFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleDiscountFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: DiscountFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Discount> => {
|
||||
@@ -37,7 +37,7 @@ export const simpleDiscountFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const ruleData = data.rule ?? ({} as DiscountRuleFactoryData)
|
||||
const ruleToSave = manager.create(DiscountRule, {
|
||||
@@ -51,7 +51,7 @@ export const simpleDiscountFactory = async (
|
||||
if (data?.rule?.conditions) {
|
||||
for (const condition of data.rule.conditions) {
|
||||
await simpleDiscountConditionFactory(
|
||||
connection,
|
||||
dataSource,
|
||||
{ ...condition, rule_id: dRule.id },
|
||||
1
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GiftCard } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
export type GiftCardFactoryData = {
|
||||
id?: string
|
||||
@@ -12,7 +12,7 @@ export type GiftCardFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleGiftCardFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: GiftCardFactoryData,
|
||||
seed?: number
|
||||
): Promise<GiftCard> => {
|
||||
@@ -20,7 +20,7 @@ export const simpleGiftCardFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const toSave = manager.create(GiftCard, {
|
||||
id: data.id,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { LineItem, LineItemAdjustment, LineItemTaxLine } from "@medusajs/medusa"
|
||||
|
||||
@@ -36,7 +36,7 @@ export type LineItemFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleLineItemFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: LineItemFactoryData,
|
||||
seed?: number
|
||||
): Promise<LineItem> => {
|
||||
@@ -52,7 +52,7 @@ export const simpleLineItemFactory = async (
|
||||
Math
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const id = data.id || `simple-line-${Math.random() * 1000}`
|
||||
const toSave = manager.create(LineItem, {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { OrderFactoryData, simpleOrderFactory } from "./simple-order-factory"
|
||||
import { OrderEdit } from "@medusajs/medusa"
|
||||
|
||||
@@ -22,13 +22,13 @@ export type OrderEditFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleOrderEditFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: OrderEditFactoryData = {}
|
||||
): Promise<OrderEdit> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
if (!data.order_id) {
|
||||
const order = await simpleOrderFactory(connection, data.order)
|
||||
const order = await simpleOrderFactory(dataSource, data.order)
|
||||
data.order_id = order.id
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import {
|
||||
Discount,
|
||||
@@ -51,7 +51,7 @@ export type OrderFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleOrderFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: OrderFactoryData = {} as OrderFactoryData,
|
||||
seed?: number
|
||||
): Promise<Order> => {
|
||||
@@ -59,7 +59,7 @@ export const simpleOrderFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let currencyCode: string
|
||||
let regionId: string
|
||||
@@ -70,16 +70,16 @@ export const simpleOrderFactory = async (
|
||||
regionId = data.region
|
||||
taxRate = data.tax_rate as number
|
||||
} else {
|
||||
const region = await simpleRegionFactory(connection, data.region)
|
||||
const region = await simpleRegionFactory(dataSource, data.region)
|
||||
taxRate =
|
||||
(typeof data.tax_rate !== "undefined" ? data.tax_rate : region.tax_rate) as number
|
||||
currencyCode = region.currency_code
|
||||
regionId = region.id
|
||||
}
|
||||
|
||||
const address = await simpleAddressFactory(connection, data.shipping_address)
|
||||
const address = await simpleAddressFactory(dataSource, data.shipping_address)
|
||||
|
||||
const customer = await simpleCustomerFactory(connection, {
|
||||
const customer = await simpleCustomerFactory(dataSource, {
|
||||
...data.customer,
|
||||
email: data.email ?? undefined,
|
||||
})
|
||||
@@ -87,14 +87,14 @@ export const simpleOrderFactory = async (
|
||||
let discounts: Discount[] = []
|
||||
if (typeof data.discounts !== "undefined") {
|
||||
discounts = await Promise.all(
|
||||
data.discounts.map((d) => simpleDiscountFactory(connection, d, seed))
|
||||
data.discounts.map((d) => simpleDiscountFactory(dataSource, d, seed))
|
||||
)
|
||||
}
|
||||
|
||||
let sales_channel
|
||||
if (typeof data.sales_channel !== "undefined") {
|
||||
sales_channel = await simpleSalesChannelFactory(
|
||||
connection,
|
||||
dataSource,
|
||||
data.sales_channel
|
||||
)
|
||||
}
|
||||
@@ -120,7 +120,7 @@ export const simpleOrderFactory = async (
|
||||
|
||||
const shippingMethods = data.shipping_methods || []
|
||||
for (const sm of shippingMethods) {
|
||||
await simpleShippingMethodFactory(connection, { ...sm, order_id: order.id })
|
||||
await simpleShippingMethodFactory(dataSource, { ...sm, order_id: order.id })
|
||||
}
|
||||
|
||||
const items =
|
||||
@@ -136,7 +136,7 @@ export const simpleOrderFactory = async (
|
||||
}) || []
|
||||
|
||||
for (const item of items) {
|
||||
await simpleLineItemFactory(connection, { ...item, order_id: id } as unknown as LineItemFactoryData)
|
||||
await simpleLineItemFactory(dataSource, { ...item, order_id: id } as unknown as LineItemFactoryData)
|
||||
}
|
||||
|
||||
return order
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import {
|
||||
OrderEdit,
|
||||
OrderEditItemChangeType,
|
||||
OrderItemChange,
|
||||
} from "@medusajs/medusa"
|
||||
import { Connection } from "typeorm"
|
||||
import { OrderEditItemChangeType, OrderItemChange } from "@medusajs/medusa"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
type OrderItemChangeData = {
|
||||
id: string
|
||||
@@ -14,10 +10,10 @@ type OrderItemChangeData = {
|
||||
}
|
||||
|
||||
export const simpleOrderItemChangeFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: OrderItemChangeData
|
||||
) => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
const change = manager.create<OrderItemChange>(OrderItemChange, {
|
||||
id: data.id,
|
||||
type: data.type,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
import { simpleRegionFactory } from "./simple-region-factory"
|
||||
import { simplePaymentFactory } from "./simple-payment-factory"
|
||||
import { Payment, PaymentCollection } from "@medusajs/medusa"
|
||||
|
||||
export const simplePaymentCollectionFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: Partial<PaymentCollection> = {}
|
||||
): Promise<PaymentCollection> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const defaultData = {
|
||||
currency_code: data.currency_code ?? "usd",
|
||||
@@ -19,7 +19,7 @@ export const simplePaymentCollectionFactory = async (
|
||||
}
|
||||
|
||||
if (!data.region && !data.region_id) {
|
||||
data.region = await simpleRegionFactory(connection, {
|
||||
data.region = await simpleRegionFactory(dataSource, {
|
||||
id: data.region_id || "test-region",
|
||||
currency_code: defaultData.currency_code,
|
||||
})
|
||||
@@ -32,7 +32,7 @@ export const simplePaymentCollectionFactory = async (
|
||||
payment.currency_code = payment.currency_code ?? defaultData.currency_code
|
||||
|
||||
const savedPayment = await simplePaymentFactory(
|
||||
connection,
|
||||
dataSource,
|
||||
payment as any
|
||||
)
|
||||
payments.push(savedPayment)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { Payment } from "@medusajs/medusa"
|
||||
|
||||
export type PaymentFactoryData = {
|
||||
@@ -12,11 +12,11 @@ export type PaymentFactoryData = {
|
||||
}
|
||||
|
||||
export const simplePaymentFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: PaymentFactoryData,
|
||||
_?: number
|
||||
): Promise<Payment> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let captured_at = data.captured
|
||||
if (typeof captured_at === "boolean") {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
PriceListType,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { simpleCustomerGroupFactory } from "./simple-customer-group-factory"
|
||||
|
||||
type ProductListPrice = {
|
||||
@@ -30,7 +30,7 @@ export type PriceListFactoryData = {
|
||||
}
|
||||
|
||||
export const simplePriceListFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: PriceListFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<PriceList> => {
|
||||
@@ -38,7 +38,7 @@ export const simplePriceListFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const listId = data.id || `simple-price-list-${Math.random() * 1000}`
|
||||
|
||||
@@ -46,7 +46,7 @@ export const simplePriceListFactory = async (
|
||||
if (typeof data.customer_groups !== "undefined") {
|
||||
customerGroups = await Promise.all(
|
||||
data.customer_groups.map((group) =>
|
||||
simpleCustomerGroupFactory(connection, { id: group })
|
||||
simpleCustomerGroupFactory(dataSource, { id: group })
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { ProductCategory } from "@medusajs/medusa"
|
||||
|
||||
export const simpleProductCategoryFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: Partial<ProductCategory> = {}
|
||||
): Promise<ProductCategory> => {
|
||||
const manager = connection.manager
|
||||
const category = manager.create(ProductCategory, data)
|
||||
const manager = dataSource.manager
|
||||
const productCategory = manager.create(ProductCategory, data)
|
||||
|
||||
return await manager.save(category)
|
||||
return await manager.save(productCategory)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { ProductCollection } from "@medusajs/medusa"
|
||||
|
||||
@@ -11,7 +11,7 @@ export const simpleProductCollectionFactory = async <
|
||||
TData extends Data | Data[] = Data | Data[],
|
||||
TResult = TData extends Array<Data> ? ProductCollection[] : ProductCollection
|
||||
>(
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data?: TData,
|
||||
seed?: number
|
||||
): Promise<TResult> => {
|
||||
@@ -19,7 +19,7 @@ export const simpleProductCollectionFactory = async <
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
data = data || [{
|
||||
title: faker.datatype.string(10),
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Store,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import {
|
||||
ProductVariantFactoryData,
|
||||
simpleProductVariantFactory,
|
||||
@@ -32,22 +32,26 @@ export type ProductFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleProductFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ProductFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Product | undefined> => {
|
||||
): Promise<Product | undefined | null> => {
|
||||
if (typeof seed !== "undefined") {
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: ShippingProfileType.DEFAULT,
|
||||
where: {
|
||||
type: ShippingProfileType.DEFAULT,
|
||||
}
|
||||
})
|
||||
|
||||
const gcProfile = await manager.findOne(ShippingProfile, {
|
||||
type: ShippingProfileType.GIFT_CARD,
|
||||
where: {
|
||||
type: ShippingProfileType.GIFT_CARD,
|
||||
}
|
||||
})
|
||||
|
||||
let sales_channels
|
||||
@@ -55,18 +59,20 @@ export const simpleProductFactory = async (
|
||||
sales_channels = await Promise.all(
|
||||
data.sales_channels.map(
|
||||
async (salesChannel) =>
|
||||
await simpleSalesChannelFactory(connection, salesChannel)
|
||||
await simpleSalesChannelFactory(dataSource, salesChannel)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
const store = await manager.findOne(Store, {
|
||||
relations: ["default_sales_channel"],
|
||||
const stores = await manager.find(Store, {
|
||||
relations: { default_sales_channel: true },
|
||||
})
|
||||
|
||||
const store = stores[0]
|
||||
|
||||
if (store?.default_sales_channel) {
|
||||
sales_channels = [store.default_sales_channel]
|
||||
} else {
|
||||
const salesChannel = await simpleSalesChannelFactory(connection, {
|
||||
const salesChannel = await simpleSalesChannelFactory(dataSource, {
|
||||
id: `default-${Math.random() * 1000}`,
|
||||
is_default: true,
|
||||
})
|
||||
@@ -144,12 +150,16 @@ export const simpleProductFactory = async (
|
||||
{ option_id: optionId, value: faker.commerce.productAdjective() },
|
||||
]
|
||||
}
|
||||
await simpleProductVariantFactory(connection, factoryData)
|
||||
await simpleProductVariantFactory(dataSource, factoryData)
|
||||
}
|
||||
|
||||
return await manager.findOne(
|
||||
Product,
|
||||
{ id: prodId },
|
||||
{ relations: ["tags", "variants", "variants.prices"] }
|
||||
{
|
||||
where: {
|
||||
id: prodId
|
||||
},
|
||||
relations: { tags: true, variants: { prices: true }}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { ProductTaxRate, TaxRate } from "@medusajs/medusa"
|
||||
|
||||
@@ -15,7 +15,7 @@ export type ProductTaxRateFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleProductTaxRateFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ProductTaxRateFactoryData,
|
||||
seed?: number
|
||||
): Promise<ProductTaxRate> => {
|
||||
@@ -23,7 +23,7 @@ export const simpleProductTaxRateFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let rateId: string
|
||||
if (typeof data.rate === "string") {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { ProductTypeTaxRate, TaxRate } from "@medusajs/medusa"
|
||||
|
||||
@@ -15,7 +15,7 @@ export type ProductTypeTaxRateFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleProductTypeTaxRateFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ProductTypeTaxRateFactoryData,
|
||||
seed?: number
|
||||
): Promise<ProductTypeTaxRate> => {
|
||||
@@ -23,7 +23,7 @@ export const simpleProductTypeTaxRateFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let rateId: string
|
||||
if (typeof data.rate === "string") {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import {
|
||||
MoneyAmount,
|
||||
ProductOptionValue,
|
||||
ProductVariant,
|
||||
MoneyAmount,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
export type ProductVariantFactoryData = {
|
||||
@@ -18,7 +18,7 @@ export type ProductVariantFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleProductVariantFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ProductVariantFactoryData,
|
||||
seed?: number
|
||||
): Promise<ProductVariant> => {
|
||||
@@ -26,7 +26,7 @@ export const simpleProductVariantFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const id = data.id || `simple-variant-${Math.random() * 1000}`
|
||||
const toSave = manager.create(ProductVariant, {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
import { PublishableApiKey } from "@medusajs/medusa"
|
||||
|
||||
@@ -12,10 +12,10 @@ export type PublishableApiKeyData = {
|
||||
}
|
||||
|
||||
export const simplePublishableApiKeyFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: PublishableApiKeyData = {}
|
||||
): Promise<PublishableApiKey> => {
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const pubKey = manager.create(PublishableApiKey, {
|
||||
...data,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { Region } from "@medusajs/medusa"
|
||||
|
||||
@@ -15,7 +15,7 @@ export type RegionFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleRegionFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: RegionFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<Region> => {
|
||||
@@ -23,7 +23,7 @@ export const simpleRegionFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const regionId = data.id || `simple-region-${Math.random() * 1000}`
|
||||
const r = manager.create(Region, {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { Product, SalesChannel } from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
|
||||
export type SalesChannelFactoryData = {
|
||||
name?: string
|
||||
description?: string
|
||||
is_disabled?: boolean
|
||||
id?: string
|
||||
products?: Product[],
|
||||
products?: Product[]
|
||||
is_default?: boolean
|
||||
}
|
||||
|
||||
export const simpleSalesChannelFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: SalesChannelFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<SalesChannel> => {
|
||||
@@ -20,7 +20,7 @@ export const simpleSalesChannelFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let salesChannel = manager.create(SalesChannel, {
|
||||
id: data.id ?? `simple-id-${Math.random() * 1000}`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { ShippingMethodTaxLine, ShippingMethod } from "@medusajs/medusa"
|
||||
import { ShippingMethod, ShippingMethodTaxLine } from "@medusajs/medusa"
|
||||
|
||||
import {
|
||||
ShippingOptionFactoryData,
|
||||
@@ -19,7 +19,7 @@ export type ShippingMethodFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleShippingMethodFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ShippingMethodFactoryData,
|
||||
seed?: number
|
||||
): Promise<ShippingMethod> => {
|
||||
@@ -27,14 +27,14 @@ export const simpleShippingMethodFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let shippingOptionId: string
|
||||
if (typeof data.shipping_option === "string") {
|
||||
shippingOptionId = data.shipping_option
|
||||
} else {
|
||||
const option = await simpleShippingOptionFactory(
|
||||
connection,
|
||||
dataSource,
|
||||
data.shipping_option
|
||||
)
|
||||
shippingOptionId = option.id
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ShippingProfileType,
|
||||
} from "@medusajs/medusa"
|
||||
import faker from "faker"
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import { simpleRegionFactory } from "./simple-region-factory"
|
||||
|
||||
export type ShippingOptionFactoryData = {
|
||||
@@ -28,7 +28,7 @@ type ShippingOptionRequirementData = {
|
||||
}
|
||||
|
||||
export const simpleShippingOptionFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ShippingOptionFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<ShippingOption> => {
|
||||
@@ -36,19 +36,23 @@ export const simpleShippingOptionFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: ShippingProfileType.DEFAULT,
|
||||
where: {
|
||||
type: ShippingProfileType.DEFAULT,
|
||||
}
|
||||
})
|
||||
|
||||
const gcProfile = await manager.findOne(ShippingProfile, {
|
||||
type: ShippingProfileType.GIFT_CARD,
|
||||
where: {
|
||||
type: ShippingProfileType.GIFT_CARD,
|
||||
}
|
||||
})
|
||||
|
||||
let region_id = data.region_id
|
||||
|
||||
if (!region_id) {
|
||||
const { id } = await simpleRegionFactory(connection)
|
||||
const { id } = await simpleRegionFactory(dataSource)
|
||||
region_id = id
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { ShippingTaxRate, TaxRate } from "@medusajs/medusa"
|
||||
|
||||
@@ -15,7 +15,7 @@ export type ShippingTaxRateFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleShippingTaxRateFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: ShippingTaxRateFactoryData,
|
||||
seed?: number
|
||||
): Promise<ShippingTaxRate> => {
|
||||
@@ -23,7 +23,7 @@ export const simpleShippingTaxRateFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
let rateId: string
|
||||
if (typeof data.rate === "string") {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Connection } from "typeorm"
|
||||
import { DataSource } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { TaxRate } from "@medusajs/medusa"
|
||||
|
||||
@@ -10,7 +10,7 @@ export type TaxRateFactoryData = {
|
||||
}
|
||||
|
||||
export const simpleTaxRateFactory = async (
|
||||
connection: Connection,
|
||||
dataSource: DataSource,
|
||||
data: TaxRateFactoryData,
|
||||
seed?: number
|
||||
): Promise<TaxRate> => {
|
||||
@@ -18,7 +18,7 @@ export const simpleTaxRateFactory = async (
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
const manager = dataSource.manager
|
||||
|
||||
const toSave = manager.create(TaxRate, {
|
||||
region_id: data.region_id,
|
||||
|
||||
Reference in new issue
Block a user