11package utils .seeds
22
3- import scala . concurrent . ExecutionContext . Implicits . global
3+ import java . time . Instant
44
5+ import scala .concurrent .ExecutionContext .Implicits .global
56import models .account ._
67import models .objects ._
78import models .product .SimpleContext
@@ -38,15 +39,15 @@ trait PromotionSeeds {
3839 for {
3940 context ← * <~ ObjectContexts .mustFindById404(SimpleContext .id)
4041 results ← * <~ discounts.map { discount ⇒
41- val payload = createPromotion(discount.title, Promotion .Coupon )
42- insertPromotion(payload, discount, context)
42+ val payload = createPromotion(Promotion .Coupon )
43+ insertPromotion(payload, discount, context, discount.title )
4344 }
4445 } yield results
4546
46- def insertPromotion (payload : CreatePromotion , discount : BaseDiscount , context : ObjectContext )(
47- implicit db : DB ,
48- ac : AC ,
49- au : AU ): DbResultT [BasePromotion ] =
47+ def insertPromotion (payload : CreatePromotion ,
48+ discount : BaseDiscount ,
49+ context : ObjectContext ,
50+ name : String )( implicit db : DB , ac : AC , au : AU ): DbResultT [BasePromotion ] =
5051 for {
5152 scope ← * <~ Scope .resolveOverride(payload.scope)
5253 form ← * <~ ObjectForm (kind = Promotion .kind, attributes = payload.form.attributes)
@@ -58,19 +59,20 @@ trait PromotionSeeds {
5859 applyType = payload.applyType,
5960 formId = ins.form.id,
6061 shadowId = ins.shadow.id,
61- commitId = ins.commit.id))
62+ commitId = ins.commit.id,
63+ name = name,
64+ activeFrom = Some (Instant .now),
65+ activeTo = None ))
6266 link ← * <~ PromotionDiscountLinks .create(
6367 PromotionDiscountLink (leftId = promotion.id, rightId = discount.discountId))
6468 } yield
6569 BasePromotion (promotion.id, ins.form.id, ins.shadow.id, payload.applyType, discount.title)
6670
67- def createPromotion (name : String , applyType : Promotion .ApplyType ): CreatePromotion = {
68- val promotionForm = BasePromotionForm (name, applyType)
69- val promotionShadow = BasePromotionShadow (promotionForm)
70-
71+ def createPromotion (applyType : Promotion .ApplyType ): CreatePromotion = {
7172 CreatePromotion (
7273 applyType = applyType,
73- form = CreatePromotionForm (attributes = promotionForm.form, discounts = Seq .empty),
74- shadow = CreatePromotionShadow (attributes = promotionShadow.shadow, discounts = Seq .empty))
74+ form = CreatePromotionForm (attributes = BasePromotionForm .form, discounts = Seq .empty),
75+ shadow =
76+ CreatePromotionShadow (attributes = BasePromotionShadow .shadow, discounts = Seq .empty))
7577 }
7678}
0 commit comments