feat(pricing,types): price list API + price calculations with price lists (#5498)
**what:** **PriceList Service APIs:** - createPriceList - updatePriceList - addPriceListPrices - removePriceListRules - setPriceListRules - deletePriceList - listPriceLists - listAndCountPriceLists **Price Calculations** - Returns prices with price list prices - Returns a new shape with calculated and original prices Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
co-authored by
Philip Korsholm
parent
2947f57db1
commit
1772e80ed1
@@ -0,0 +1,12 @@
|
||||
export const defaultPriceListRuleData = [
|
||||
{
|
||||
id: "price-list-rule-1",
|
||||
price_list: "price-list-1",
|
||||
rule_type: "rule-type-1",
|
||||
},
|
||||
{
|
||||
id: "price-list-rule-2",
|
||||
price_list: "price-list-1",
|
||||
rule_type: "rule-type-2",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceListRule } from "@models"
|
||||
import { defaultPriceListRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceListRules(
|
||||
manager: SqlEntityManager,
|
||||
priceListRuleData: any[] = defaultPriceListRuleData
|
||||
): Promise<PriceListRule[]> {
|
||||
const priceListRules: PriceListRule[] = []
|
||||
|
||||
for (let data of priceListRuleData) {
|
||||
const plr = manager.create(PriceListRule, data)
|
||||
|
||||
priceListRules.push(plr)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceListRules)
|
||||
|
||||
return priceListRules
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export const defaultPriceListData = [
|
||||
{
|
||||
id: "price-list-1",
|
||||
title: "Price List 1",
|
||||
description: "test",
|
||||
number_rules: 0,
|
||||
},
|
||||
{
|
||||
id: "price-list-2",
|
||||
title: "Price List 2",
|
||||
description: "test",
|
||||
number_rules: 0,
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceList } from "@models"
|
||||
import { defaultPriceListData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceLists(
|
||||
manager: SqlEntityManager,
|
||||
priceListData: any[] = defaultPriceListData
|
||||
): Promise<PriceList[]> {
|
||||
const priceLists: PriceList[] = []
|
||||
|
||||
for (let data of priceListData) {
|
||||
const pl = manager.create(PriceList, data)
|
||||
|
||||
priceLists.push(pl)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceLists)
|
||||
|
||||
return priceLists
|
||||
}
|
||||
Reference in New Issue
Block a user