feat(types,utils): add promotions create with application method (#5945)
What: - Promotions can be created with its bare attributes - Promotions one to one relationship with ApplicationMethod can be created with its attributes + validation RESOLVES CORE-1592 RESOLVES CORE-1595
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { PromotionType } from "@medusajs/utils"
|
||||
|
||||
export const defaultPromotionsData = [
|
||||
{
|
||||
id: "promotion-id-1",
|
||||
code: "PROMOTION_1",
|
||||
type: PromotionType.STANDARD,
|
||||
},
|
||||
{
|
||||
id: "promotion-id-2",
|
||||
code: "PROMOTION_2",
|
||||
type: PromotionType.STANDARD,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Promotion } from "@models"
|
||||
import { defaultPromotionsData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPromotions(
|
||||
manager: SqlEntityManager,
|
||||
promotionsData = defaultPromotionsData
|
||||
): Promise<Promotion[]> {
|
||||
const promotion: Promotion[] = []
|
||||
|
||||
for (let promotionData of promotionsData) {
|
||||
let promotion = manager.create(Promotion, promotionData)
|
||||
|
||||
manager.persist(promotion)
|
||||
|
||||
await manager.flush()
|
||||
}
|
||||
|
||||
return promotion
|
||||
}
|
||||
Reference in New Issue
Block a user