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:
Riqwan Thamir authored and GitHub committed 2024-09-05 15:45:30 +02:00
1 parent 440f598de8
commit 0573bb924a
124 files changed
+80 -1386

No files matched your search

@@ -0,0 +1,58 @@
import {
AllocationType,
Discount,
DiscountRule,
DiscountRuleType,
} from "@medusajs/medusa"
import faker from "faker"
import { DataSource } from "typeorm"
export type DiscountRuleFactoryData = {
type?: DiscountRuleType
value?: number
allocation?: AllocationType
}
export type DiscountFactoryData = {
id?: string
code?: string
is_dynamic?: boolean
rule?: DiscountRuleFactoryData
regions?: string[]
starts_at?: Date
ends_at?: Date
}
export const simpleDiscountFactory = async (
dataSource: DataSource,
data: DiscountFactoryData = {},
seed?: number
): Promise<Discount> => {
if (typeof seed !== "undefined") {
faker.seed(seed)
}
const manager = dataSource.manager
const ruleData = data.rule ?? ({} as DiscountRuleFactoryData)
const ruleToSave = manager.create(DiscountRule, {
type: ruleData.type ?? DiscountRuleType.PERCENTAGE,
value: ruleData.value ?? 10,
allocation: ruleData.allocation ?? AllocationType.TOTAL,
})
const dRule = await manager.save(ruleToSave)
const toSave = manager.create(Discount, {
id: data.id,
is_dynamic: data.is_dynamic ?? false,
is_disabled: false,
rule_id: dRule.id,
code: data.code ?? "TESTCODE",
regions: data.regions?.map((r) => ({ id: r })) || [],
starts_at: data.starts_at,
ends_at: data.ends_at,
})
return await manager.save(toSave)
}