@medusajs/pricing 0.2.0-snapshot-20240412124109 → 0.2.0-snapshot-20240423083106
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/joiner-config.d.ts +1 -0
- package/dist/joiner-config.js +13 -0
- package/dist/migrations/Migration20230929122253.js +1 -1
- package/dist/models/price.d.ts +3 -1
- package/dist/models/price.js +6 -2
- package/dist/services/pricing-module.d.ts +5 -5
- package/dist/services/pricing-module.js +23 -25
- package/package.json +5 -5
package/dist/joiner-config.d.ts
CHANGED
package/dist/joiner-config.js
CHANGED
@@ -11,6 +11,7 @@ exports.LinkableKeys = {
|
|
11
11
|
price_set_id: _models_1.PriceSet.name,
|
12
12
|
price_list_id: _models_1.PriceList.name,
|
13
13
|
price_id: _models_1.Price.name,
|
14
|
+
rule_type_id: _models_1.RuleType.name,
|
14
15
|
};
|
15
16
|
const entityLinkableKeysMap = {};
|
16
17
|
Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
|
@@ -39,5 +40,17 @@ exports.joinerConfig = {
|
|
39
40
|
methodSuffix: "PriceLists",
|
40
41
|
},
|
41
42
|
},
|
43
|
+
{
|
44
|
+
name: ["price", "prices"],
|
45
|
+
args: {
|
46
|
+
methodSuffix: "Prices",
|
47
|
+
},
|
48
|
+
},
|
49
|
+
{
|
50
|
+
name: ["rule_type", "rule_types"],
|
51
|
+
args: {
|
52
|
+
methodSuffix: "RuleTypes",
|
53
|
+
},
|
54
|
+
},
|
42
55
|
],
|
43
56
|
};
|
@@ -6,7 +6,7 @@ class Migration20230929122253 extends migrations_1.Migration {
|
|
6
6
|
async up() {
|
7
7
|
this.addSql('create table if not exists "money_amount" ("id" text not null, "currency_code" text not null, "amount" numeric not null, "min_quantity" numeric null, "max_quantity" numeric null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "money_amount_pkey" primary key ("id"));');
|
8
8
|
this.addSql('create table "price_set" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_pkey" primary key ("id"));');
|
9
|
-
this.addSql('create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));');
|
9
|
+
this.addSql('create table "price" ("id" text not null, "title" text, "price_set_id" text not null, "money_amount_id" text not null, "raw_amount" jsonb not null, "rules_count" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_pkey" primary key ("id"));');
|
10
10
|
this.addSql('alter table "price" add constraint "price_money_amount_id_unique" unique ("money_amount_id");');
|
11
11
|
this.addSql('create table "rule_type" ("id" text not null, "name" text not null, "rule_attribute" text not null, "default_priority" integer not null default 0, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rule_type_pkey" primary key ("id"));');
|
12
12
|
this.addSql('create table "price_set_rule_type" ("id" text not null, "price_set_id" text not null, "rule_type_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "price_set_rule_type_pkey" primary key ("id"));');
|
package/dist/models/price.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { DAL } from "@medusajs/types";
|
2
|
+
import { BigNumber } from "@medusajs/utils";
|
2
3
|
import { Collection, OptionalProps } from "@mikro-orm/core";
|
3
4
|
import PriceList from "./price-list";
|
4
5
|
import PriceRule from "./price-rule";
|
@@ -9,7 +10,8 @@ export default class Price {
|
|
9
10
|
id: string;
|
10
11
|
title: string | null;
|
11
12
|
currency_code: string;
|
12
|
-
amount: number;
|
13
|
+
amount: BigNumber | number;
|
14
|
+
raw_amount: Record<string, unknown>;
|
13
15
|
min_quantity: number | null;
|
14
16
|
max_quantity: number | null;
|
15
17
|
price_set_id: string;
|
package/dist/models/price.js
CHANGED
@@ -74,9 +74,13 @@ __decorate([
|
|
74
74
|
__metadata("design:type", String)
|
75
75
|
], Price.prototype, "currency_code", void 0);
|
76
76
|
__decorate([
|
77
|
-
(0,
|
78
|
-
__metadata("design:type",
|
77
|
+
(0, utils_1.MikroOrmBigNumberProperty)(),
|
78
|
+
__metadata("design:type", Object)
|
79
79
|
], Price.prototype, "amount", void 0);
|
80
|
+
__decorate([
|
81
|
+
(0, core_1.Property)({ columnType: "jsonb" }),
|
82
|
+
__metadata("design:type", Object)
|
83
|
+
], Price.prototype, "raw_amount", void 0);
|
80
84
|
__decorate([
|
81
85
|
(0, core_1.Property)({ columnType: "numeric", nullable: true }),
|
82
86
|
__metadata("design:type", Object)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AddPricesDTO, Context, DAL, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, RuleTypeDTO, UpsertPriceSetDTO } from "@medusajs/types";
|
1
|
+
import { AddPricesDTO, Context, CreatePriceRuleDTO, DAL, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, RuleTypeDTO, UpsertPriceSetDTO } from "@medusajs/types";
|
2
2
|
import { ModulesSdkUtils } from "@medusajs/utils";
|
3
3
|
import { Price, PriceList, PriceListRule, PriceListRuleValue, PriceRule, PriceSet, PriceSetRuleType, RuleType } from "../models";
|
4
4
|
import { PriceListService, RuleTypeService } from ".";
|
@@ -69,9 +69,9 @@ export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet,
|
|
69
69
|
createPriceListRules(data: PricingTypes.CreatePriceListRuleDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListRuleDTO[]>;
|
70
70
|
createPriceListRules_(data: PricingTypes.CreatePriceListRuleDTO[], sharedContext?: Context): Promise<TPriceListRule[]>;
|
71
71
|
updatePriceListRules(data: PricingTypes.UpdatePriceListRuleDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListRuleDTO[]>;
|
72
|
-
updatePriceListPrices(data: PricingTypes.UpdatePriceListPricesDTO[], sharedContext?: Context): Promise<PricingTypes.
|
72
|
+
updatePriceListPrices(data: PricingTypes.UpdatePriceListPricesDTO[], sharedContext?: Context): Promise<PricingTypes.PriceDTO[]>;
|
73
73
|
removePrices(ids: string[], sharedContext?: Context): Promise<void>;
|
74
|
-
addPriceListPrices(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<PricingTypes.
|
74
|
+
addPriceListPrices(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<PricingTypes.PriceDTO[]>;
|
75
75
|
setPriceListRules(data: PricingTypes.SetPriceListRulesDTO, sharedContext?: Context): Promise<PricingTypes.PriceListDTO>;
|
76
76
|
removePriceListRules(data: PricingTypes.RemovePriceListRulesDTO, sharedContext?: Context): Promise<PricingTypes.PriceListDTO>;
|
77
77
|
protected create_(data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context): Promise<TPriceSet[]>;
|
@@ -79,9 +79,9 @@ export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet,
|
|
79
79
|
protected addPrices_(input: AddPricesDTO[], sharedContext?: Context): Promise<void>;
|
80
80
|
protected createPriceLists_(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<TPriceList[]>;
|
81
81
|
protected updatePriceLists_(data: PricingTypes.UpdatePriceListDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListDTO[]>;
|
82
|
-
protected updatePriceListPrices_(data: PricingTypes.UpdatePriceListPricesDTO[], sharedContext?: Context): Promise<
|
82
|
+
protected updatePriceListPrices_(data: PricingTypes.UpdatePriceListPricesDTO[], sharedContext?: Context): Promise<TPrice[]>;
|
83
83
|
protected removePrices_(ids: string[], sharedContext?: Context): Promise<void>;
|
84
|
-
protected addPriceListPrices_(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<
|
84
|
+
protected addPriceListPrices_(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<TPrice[]>;
|
85
85
|
protected setPriceListRules_(data: PricingTypes.SetPriceListRulesDTO[], sharedContext?: Context): Promise<TPriceList[]>;
|
86
86
|
protected removePriceListRules_(data: PricingTypes.RemovePriceListRulesDTO[], sharedContext?: Context): Promise<TPriceList[]>;
|
87
87
|
}
|
@@ -17,8 +17,8 @@ const utils_1 = require("@medusajs/utils");
|
|
17
17
|
const _models_1 = require("../models");
|
18
18
|
const _utils_1 = require("../utils");
|
19
19
|
const joiner_config_1 = require("../joiner-config");
|
20
|
-
const price_set_1 = require("../models/price-set");
|
21
20
|
const price_list_1 = require("../models/price-list");
|
21
|
+
const price_set_1 = require("../models/price-set");
|
22
22
|
const generateMethodForModels = [
|
23
23
|
_models_1.PriceList,
|
24
24
|
_models_1.PriceListRule,
|
@@ -159,7 +159,7 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
|
|
159
159
|
...price,
|
160
160
|
price_set_id: priceSet.id,
|
161
161
|
price_rules: hasRulesInput ? rules : undefined,
|
162
|
-
rules_count: hasRulesInput ? rules.length : undefined
|
162
|
+
rules_count: hasRulesInput ? rules.length : undefined,
|
163
163
|
};
|
164
164
|
});
|
165
165
|
return {
|
@@ -246,13 +246,15 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
|
|
246
246
|
});
|
247
247
|
}
|
248
248
|
async updatePriceListPrices(data, sharedContext = {}) {
|
249
|
-
|
249
|
+
const prices = await this.updatePriceListPrices_(data, sharedContext);
|
250
|
+
return await this.baseRepository_.serialize(prices);
|
250
251
|
}
|
251
252
|
async removePrices(ids, sharedContext = {}) {
|
252
253
|
await this.removePrices_(ids, sharedContext);
|
253
254
|
}
|
254
255
|
async addPriceListPrices(data, sharedContext = {}) {
|
255
|
-
|
256
|
+
const prices = await this.addPriceListPrices_(data, sharedContext);
|
257
|
+
return await this.baseRepository_.serialize(prices);
|
256
258
|
}
|
257
259
|
async setPriceListRules(data, sharedContext = {}) {
|
258
260
|
const [priceList] = await this.setPriceListRules_([data], sharedContext);
|
@@ -562,40 +564,37 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
|
|
562
564
|
}
|
563
565
|
const priceLists = await this.listPriceLists({ id: priceListIds }, { take: null }, sharedContext);
|
564
566
|
const priceListMap = new Map(priceLists.map((p) => [p.id, p]));
|
567
|
+
const pricesToUpdate = [];
|
568
|
+
const priceRuleIdsToDelete = [];
|
569
|
+
const priceRulesToCreate = [];
|
565
570
|
for (const { price_list_id: priceListId, prices } of data) {
|
566
571
|
const priceList = priceListMap.get(priceListId);
|
567
572
|
if (!priceList) {
|
568
573
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Price list with id: ${priceListId} not found`);
|
569
574
|
}
|
570
|
-
const priceRuleIdsToDelete = [];
|
571
|
-
const priceRulesToCreate = [];
|
572
|
-
const pricesToUpdate = [];
|
573
575
|
for (const priceData of prices) {
|
574
|
-
const { rules, price_set_id, ...rest } = priceData;
|
576
|
+
const { rules = {}, price_set_id, ...rest } = priceData;
|
575
577
|
const price = priceMap.get(rest.id);
|
576
578
|
const priceRules = price.price_rules;
|
577
|
-
|
578
|
-
|
579
|
-
|
579
|
+
priceRulesToCreate.push(...Object.entries(rules).map(([ruleAttribute, ruleValue]) => ({
|
580
|
+
price_set_id,
|
581
|
+
rule_type_id: ruleTypeMap.get(ruleAttribute).id,
|
582
|
+
value: ruleValue,
|
583
|
+
price_id: price.id,
|
584
|
+
})));
|
580
585
|
pricesToUpdate.push({
|
581
586
|
...rest,
|
582
587
|
rules_count: Object.keys(rules).length,
|
583
|
-
price_rules: Object.entries(rules).map(([ruleAttribute, ruleValue]) => ({
|
584
|
-
price_set_id,
|
585
|
-
rule_type_id: ruleTypeMap.get(ruleAttribute).id,
|
586
|
-
value: ruleValue,
|
587
|
-
price_id: price.id,
|
588
|
-
})),
|
589
588
|
});
|
590
589
|
priceRuleIdsToDelete.push(...priceRules.map((pr) => pr.id));
|
591
590
|
}
|
592
|
-
await (0, utils_1.promiseAll)([
|
593
|
-
this.priceRuleService_.delete(priceRuleIdsToDelete),
|
594
|
-
this.priceRuleService_.create(priceRulesToCreate),
|
595
|
-
this.priceService_.update(pricesToUpdate),
|
596
|
-
]);
|
597
591
|
}
|
598
|
-
|
592
|
+
const [_deletedPriceRule, _createdPriceRule, updatedPrices] = await (0, utils_1.promiseAll)([
|
593
|
+
this.priceRuleService_.delete(priceRuleIdsToDelete),
|
594
|
+
this.priceRuleService_.create(priceRulesToCreate),
|
595
|
+
this.priceService_.update(pricesToUpdate),
|
596
|
+
]);
|
597
|
+
return updatedPrices;
|
599
598
|
}
|
600
599
|
async removePrices_(ids, sharedContext = {}) {
|
601
600
|
await this.priceService_.delete(ids, sharedContext);
|
@@ -664,8 +663,7 @@ class PricingModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
|
|
664
663
|
});
|
665
664
|
pricesToCreate.push(...priceListPricesToCreate);
|
666
665
|
}
|
667
|
-
await this.priceService_.create(pricesToCreate, sharedContext);
|
668
|
-
return priceLists;
|
666
|
+
return await this.priceService_.create(pricesToCreate, sharedContext);
|
669
667
|
}
|
670
668
|
async setPriceListRules_(data, sharedContext = {}) {
|
671
669
|
// TODO: re think this method
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/pricing",
|
3
|
-
"version": "0.2.0-snapshot-
|
3
|
+
"version": "0.2.0-snapshot-20240423083106",
|
4
4
|
"description": "Medusa Pricing module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"@mikro-orm/cli": "5.9.7",
|
41
41
|
"cross-env": "^5.2.1",
|
42
42
|
"jest": "^29.6.3",
|
43
|
-
"medusa-test-utils": "1.1.44-snapshot-
|
43
|
+
"medusa-test-utils": "1.1.44-snapshot-20240423083106",
|
44
44
|
"rimraf": "^3.0.2",
|
45
45
|
"ts-jest": "^29.1.1",
|
46
46
|
"ts-node": "^10.9.1",
|
@@ -48,9 +48,9 @@
|
|
48
48
|
"typescript": "^5.1.6"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@medusajs/modules-sdk": "1.12.11-snapshot-
|
52
|
-
"@medusajs/types": "1.12.0-snapshot-
|
53
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
51
|
+
"@medusajs/modules-sdk": "1.12.11-snapshot-20240423083106",
|
52
|
+
"@medusajs/types": "1.12.0-snapshot-20240423083106",
|
53
|
+
"@medusajs/utils": "1.12.0-snapshot-20240423083106",
|
54
54
|
"@mikro-orm/core": "5.9.7",
|
55
55
|
"@mikro-orm/migrations": "5.9.7",
|
56
56
|
"@mikro-orm/postgresql": "5.9.7",
|