chore: Remove typeORM (#9005)
* chore: rename js files to txt * chore: rename ts files to txt * chore: delete environment helpers * chore: convert global setup & teardown to txt * chore: rename helper js/ts files to txt * chore: rename seeder js/ts files to txt * chore: remove typeorm * chore: reintroduce used helpers
This commit is contained in:
1 parent
440f598de8
commit
0573bb924a
124 files changed
+80
-1386
No files matched your search
@@ -0,0 +1,52 @@
|
||||
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 (
|
||||
dataSource: DataSource,
|
||||
data: Partial<PaymentCollection> = {}
|
||||
): Promise<PaymentCollection> => {
|
||||
const manager = dataSource.manager
|
||||
|
||||
const defaultData = {
|
||||
currency_code: data.currency_code ?? "usd",
|
||||
type: data.type ?? "order_edit",
|
||||
status: data.status ?? "not_paid",
|
||||
amount: data.amount ?? 1000,
|
||||
created_by: data.created_by ?? "admin_user",
|
||||
}
|
||||
|
||||
if (!data.region && !data.region_id) {
|
||||
data.region = await simpleRegionFactory(dataSource, {
|
||||
id: data.region_id || "test-region",
|
||||
currency_code: defaultData.currency_code,
|
||||
})
|
||||
data.region_id = data.region.id
|
||||
}
|
||||
|
||||
if (data.payments?.length) {
|
||||
const payments: Payment[] = []
|
||||
for (const payment of data.payments) {
|
||||
payment.currency_code = payment.currency_code ?? defaultData.currency_code
|
||||
|
||||
const savedPayment = await simplePaymentFactory(
|
||||
dataSource,
|
||||
payment as any
|
||||
)
|
||||
payments.push(savedPayment)
|
||||
}
|
||||
|
||||
data.payments = payments
|
||||
}
|
||||
|
||||
const obj = {
|
||||
...defaultData,
|
||||
...data,
|
||||
}
|
||||
|
||||
const payCol = manager.create<PaymentCollection>(PaymentCollection, obj)
|
||||
|
||||
return await manager.save<PaymentCollection>(payCol)
|
||||
}
|
||||
Reference in new issue
Block a user