feat(utils,types): campaigns and campaign budgets + services CRUD (#6063)

* chore: added item/shipping adjustments for order/items/shipping_methods

* chore: add validation for order type and target rules

* chore: add comment for applied promotions

* chore: add shipping method and item adjustments

* chore: include applied promotions to items/shipping_method for each case

* chore: handle case for items across and order to consider existing applications

* chore: handle case for applied promo values to shipping => across

* chore: added changeset

* chore: update return of function

* chore: campaigns and campaign budgets + services CRUD

* Apply suggestions from code review

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* chore: minor refactor

* chore: added single/bulk interfaces

* Apply suggestions from code review

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>

* chore: use DAL date entity

* chore: align nullable

* Update packages/promotion/src/models/promotion-rule.ts

* chore: fix types

* chore: review changes

* Update packages/promotion/src/utils/compute-actions/shipping-methods.ts

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2024-01-12 14:14:34 +01:00
committed by GitHub
co-authored by Oli Juhl Philip Korsholm
parent b782d3bcb7
commit fade8ea7bf
29 changed files with 1181 additions and 28 deletions
@@ -0,0 +1,32 @@
import { CampaignBudgetType } from "@medusajs/utils"
export const defaultCampaignsData = [
{
id: "campaign-id-1",
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-1",
starts_at: new Date("01/01/2023"),
ends_at: new Date("01/01/2024"),
budget: {
type: CampaignBudgetType.SPEND,
limit: 1000,
used: 0,
},
},
{
id: "campaign-id-2",
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-2",
starts_at: new Date("01/01/2023"),
ends_at: new Date("01/01/2024"),
budget: {
type: CampaignBudgetType.USAGE,
limit: 1000,
used: 0,
},
},
]
@@ -0,0 +1,23 @@
import { CreateCampaignDTO } from "@medusajs/types"
import { SqlEntityManager } from "@mikro-orm/postgresql"
import { Campaign } from "@models"
import { defaultCampaignsData } from "./data"
export * from "./data"
export async function createCampaigns(
manager: SqlEntityManager,
campaignsData: CreateCampaignDTO[] = defaultCampaignsData
): Promise<Campaign[]> {
const campaigns: Campaign[] = []
for (let campaignData of campaignsData) {
let campaign = manager.create(Campaign, campaignData)
manager.persist(campaign)
await manager.flush()
}
return campaigns
}