@medusajs/pricing 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/joiner-config.d.ts +1 -2
- package/dist/joiner-config.js +1 -9
- package/dist/migrations/Migration20230929122253.js +60 -29
- package/dist/migrations/Migration20240322094407.d.ts +5 -0
- package/dist/migrations/Migration20240322094407.js +15 -0
- package/dist/migrations/{Migration20231101232834.d.ts → Migration20240322113359.d.ts} +1 -1
- package/dist/migrations/Migration20240322113359.js +19 -0
- package/dist/migrations/{Migration20240103140327.d.ts → Migration20240322120125.d.ts} +1 -1
- package/dist/migrations/Migration20240322120125.js +15 -0
- package/dist/models/index.d.ts +1 -3
- package/dist/models/index.js +3 -7
- package/dist/models/price-list-rule-value.d.ts +9 -0
- package/dist/models/price-list-rule-value.js +49 -4
- package/dist/models/price-list-rule.d.ts +8 -3
- package/dist/models/price-list-rule.js +65 -15
- package/dist/models/price-list.d.ts +7 -6
- package/dist/models/price-list.js +23 -11
- package/dist/models/price-rule.d.ts +8 -5
- package/dist/models/price-rule.js +63 -19
- package/dist/models/price-set-rule-type.d.ts +5 -4
- package/dist/models/price-set-rule-type.js +57 -8
- package/dist/models/price-set.d.ts +7 -6
- package/dist/models/price-set.js +42 -19
- package/dist/models/price.d.ts +27 -0
- package/dist/models/price.js +167 -0
- package/dist/models/rule-type.d.ts +1 -0
- package/dist/models/rule-type.js +21 -2
- package/dist/repositories/pricing.js +40 -38
- package/dist/scripts/seed.js +9 -17
- package/dist/services/index.d.ts +0 -3
- package/dist/services/index.js +1 -7
- package/dist/services/pricing-module.d.ts +19 -33
- package/dist/services/pricing-module.js +163 -348
- package/dist/services/rule-type.d.ts +5 -6
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +1 -2
- package/dist/types/services/index.d.ts +0 -10
- package/dist/types/services/index.js +0 -10
- package/dist/types/services/price-list.d.ts +0 -21
- package/package.json +5 -5
- package/dist/migrations/Migration20231101232834.js +0 -50
- package/dist/migrations/Migration20240103140327.js +0 -29
- package/dist/models/money-amount.d.ts +0 -19
- package/dist/models/money-amount.js +0 -111
- package/dist/models/price-set-money-amount-rules.d.ts +0 -10
- package/dist/models/price-set-money-amount-rules.js +0 -63
- package/dist/models/price-set-money-amount.d.ts +0 -24
- package/dist/models/price-set-money-amount.js +0 -128
- package/dist/services/price-list-rule-value.d.ts +0 -13
- package/dist/services/price-list-rule-value.js +0 -22
- package/dist/services/price-list-rule.d.ts +0 -15
- package/dist/services/price-list-rule.js +0 -41
- package/dist/services/price-rule.d.ts +0 -13
- package/dist/services/price-rule.js +0 -22
- package/dist/types/repositories/index.d.ts +0 -10
- package/dist/types/repositories/index.js +0 -26
- package/dist/types/repositories/money-amount.d.ts +0 -14
- package/dist/types/repositories/money-amount.js +0 -2
- package/dist/types/repositories/price-list-rule-value.d.ts +0 -10
- package/dist/types/repositories/price-list-rule-value.js +0 -2
- package/dist/types/repositories/price-list-rule.d.ts +0 -14
- package/dist/types/repositories/price-list-rule.js +0 -2
- package/dist/types/repositories/price-list.d.ts +0 -18
- package/dist/types/repositories/price-list.js +0 -2
- package/dist/types/repositories/price-rule.d.ts +0 -21
- package/dist/types/repositories/price-rule.js +0 -2
- package/dist/types/repositories/price-set-money-amount-rules.d.ts +0 -11
- package/dist/types/repositories/price-set-money-amount-rules.js +0 -2
- package/dist/types/repositories/price-set-money-amount.d.ts +0 -13
- package/dist/types/repositories/price-set-money-amount.js +0 -2
- package/dist/types/repositories/price-set-rule-type.d.ts +0 -10
- package/dist/types/repositories/price-set-rule-type.js +0 -2
- package/dist/types/repositories/price-set.d.ts +0 -5
- package/dist/types/repositories/price-set.js +0 -2
- package/dist/types/repositories/rule-type.d.ts +0 -12
- package/dist/types/repositories/rule-type.js +0 -2
- package/dist/types/services/money-amount.d.ts +0 -30
- package/dist/types/services/money-amount.js +0 -2
- package/dist/types/services/price-list-rule-value.d.ts +0 -21
- package/dist/types/services/price-list-rule-value.js +0 -2
- package/dist/types/services/price-list-rule.d.ts +0 -27
- package/dist/types/services/price-list-rule.js +0 -2
- package/dist/types/services/price-rule.d.ts +0 -42
- package/dist/types/services/price-rule.js +0 -2
- package/dist/types/services/price-set-money-amount-rules.d.ts +0 -24
- package/dist/types/services/price-set-money-amount-rules.js +0 -2
- package/dist/types/services/price-set-money-amount.d.ts +0 -32
- package/dist/types/services/price-set-money-amount.js +0 -2
- package/dist/types/services/price-set-rule-type.d.ts +0 -21
- package/dist/types/services/price-set-rule-type.js +0 -2
- package/dist/types/services/price-set.d.ts +0 -15
- package/dist/types/services/price-set.js +0 -2
- package/dist/types/services/pricing.d.ts +0 -20
- package/dist/types/services/pricing.js +0 -2
- package/dist/types/services/rule-type.d.ts +0 -32
- package/dist/types/services/rule-type.js +0 -2
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@medusajs/utils");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const price_list_1 = __importDefault(require("./price-list"));
|
|
18
|
+
const price_rule_1 = __importDefault(require("./price-rule"));
|
|
19
|
+
const price_set_1 = __importDefault(require("./price-set"));
|
|
20
|
+
const tableName = "price";
|
|
21
|
+
const PriceDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
22
|
+
tableName: tableName,
|
|
23
|
+
columns: "deleted_at",
|
|
24
|
+
where: "deleted_at IS NOT NULL",
|
|
25
|
+
});
|
|
26
|
+
const PricePriceSetIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
27
|
+
tableName: tableName,
|
|
28
|
+
columns: "price_set_id",
|
|
29
|
+
where: "deleted_at IS NULL",
|
|
30
|
+
});
|
|
31
|
+
const PricePriceListIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
32
|
+
tableName: tableName,
|
|
33
|
+
columns: "price_list_id",
|
|
34
|
+
where: "deleted_at IS NULL",
|
|
35
|
+
});
|
|
36
|
+
const PriceCurrencyCodeIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
37
|
+
tableName: tableName,
|
|
38
|
+
columns: "currency_code",
|
|
39
|
+
where: "deleted_at IS NULL",
|
|
40
|
+
});
|
|
41
|
+
let Price = class Price {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.title = null;
|
|
44
|
+
this.min_quantity = null;
|
|
45
|
+
this.max_quantity = null;
|
|
46
|
+
this.rules_count = 0;
|
|
47
|
+
this.price_rules = new core_1.Collection(this);
|
|
48
|
+
this.price_list_id = null;
|
|
49
|
+
this.price_list = null;
|
|
50
|
+
this.deleted_at = null;
|
|
51
|
+
}
|
|
52
|
+
onCreate() {
|
|
53
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "price");
|
|
54
|
+
this.price_set_id ?? (this.price_set_id = this.price_set?.id);
|
|
55
|
+
this.price_list_id ?? (this.price_list_id = this.price_list?.id);
|
|
56
|
+
}
|
|
57
|
+
onInit() {
|
|
58
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "price");
|
|
59
|
+
this.price_set_id ?? (this.price_set_id = this.price_set?.id);
|
|
60
|
+
this.price_list_id ?? (this.price_list_id = this.price_list?.id);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
65
|
+
__metadata("design:type", String)
|
|
66
|
+
], Price.prototype, "id", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
69
|
+
__metadata("design:type", Object)
|
|
70
|
+
], Price.prototype, "title", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
PriceCurrencyCodeIndex.MikroORMIndex(),
|
|
73
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
74
|
+
__metadata("design:type", String)
|
|
75
|
+
], Price.prototype, "currency_code", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, core_1.Property)({ columnType: "numeric", serializer: Number }),
|
|
78
|
+
__metadata("design:type", Number)
|
|
79
|
+
], Price.prototype, "amount", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, core_1.Property)({ columnType: "numeric", nullable: true }),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], Price.prototype, "min_quantity", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
(0, core_1.Property)({ columnType: "numeric", nullable: true }),
|
|
86
|
+
__metadata("design:type", Object)
|
|
87
|
+
], Price.prototype, "max_quantity", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
PricePriceSetIdIndex.MikroORMIndex(),
|
|
90
|
+
(0, core_1.ManyToOne)(() => price_set_1.default, {
|
|
91
|
+
columnType: "text",
|
|
92
|
+
mapToPk: true,
|
|
93
|
+
fieldName: "price_set_id",
|
|
94
|
+
onDelete: "cascade",
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", String)
|
|
97
|
+
], Price.prototype, "price_set_id", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
(0, core_1.ManyToOne)(() => price_set_1.default, { persist: false }),
|
|
100
|
+
__metadata("design:type", price_set_1.default)
|
|
101
|
+
], Price.prototype, "price_set", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, core_1.Property)({ columnType: "integer", default: 0 }),
|
|
104
|
+
__metadata("design:type", Number)
|
|
105
|
+
], Price.prototype, "rules_count", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
(0, core_1.OneToMany)({
|
|
108
|
+
entity: () => price_rule_1.default,
|
|
109
|
+
mappedBy: (pr) => pr.price,
|
|
110
|
+
cascade: [core_1.Cascade.PERSIST, "soft-remove"],
|
|
111
|
+
}),
|
|
112
|
+
__metadata("design:type", Object)
|
|
113
|
+
], Price.prototype, "price_rules", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
PricePriceListIdIndex.MikroORMIndex(),
|
|
116
|
+
(0, core_1.ManyToOne)(() => price_list_1.default, {
|
|
117
|
+
columnType: "text",
|
|
118
|
+
mapToPk: true,
|
|
119
|
+
nullable: true,
|
|
120
|
+
fieldName: "price_list_id",
|
|
121
|
+
onDelete: "cascade",
|
|
122
|
+
}),
|
|
123
|
+
__metadata("design:type", Object)
|
|
124
|
+
], Price.prototype, "price_list_id", void 0);
|
|
125
|
+
__decorate([
|
|
126
|
+
(0, core_1.ManyToOne)(() => price_list_1.default, { persist: false, nullable: true }),
|
|
127
|
+
__metadata("design:type", Object)
|
|
128
|
+
], Price.prototype, "price_list", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, core_1.Property)({
|
|
131
|
+
onCreate: () => new Date(),
|
|
132
|
+
columnType: "timestamptz",
|
|
133
|
+
defaultRaw: "now()",
|
|
134
|
+
}),
|
|
135
|
+
__metadata("design:type", Date)
|
|
136
|
+
], Price.prototype, "created_at", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, core_1.Property)({
|
|
139
|
+
onCreate: () => new Date(),
|
|
140
|
+
onUpdate: () => new Date(),
|
|
141
|
+
columnType: "timestamptz",
|
|
142
|
+
defaultRaw: "now()",
|
|
143
|
+
}),
|
|
144
|
+
__metadata("design:type", Date)
|
|
145
|
+
], Price.prototype, "updated_at", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
PriceDeletedAtIndex.MikroORMIndex(),
|
|
148
|
+
(0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
|
|
149
|
+
__metadata("design:type", Object)
|
|
150
|
+
], Price.prototype, "deleted_at", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, core_1.BeforeCreate)(),
|
|
153
|
+
__metadata("design:type", Function),
|
|
154
|
+
__metadata("design:paramtypes", []),
|
|
155
|
+
__metadata("design:returntype", void 0)
|
|
156
|
+
], Price.prototype, "onCreate", null);
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, core_1.OnInit)(),
|
|
159
|
+
__metadata("design:type", Function),
|
|
160
|
+
__metadata("design:paramtypes", []),
|
|
161
|
+
__metadata("design:returntype", void 0)
|
|
162
|
+
], Price.prototype, "onInit", null);
|
|
163
|
+
Price = __decorate([
|
|
164
|
+
(0, core_1.Entity)({ tableName }),
|
|
165
|
+
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
|
166
|
+
], Price);
|
|
167
|
+
exports.default = Price;
|
package/dist/models/rule-type.js
CHANGED
|
@@ -15,9 +15,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const utils_1 = require("@medusajs/utils");
|
|
16
16
|
const core_1 = require("@mikro-orm/core");
|
|
17
17
|
const price_set_1 = __importDefault(require("./price-set"));
|
|
18
|
+
const tableName = "rule_type";
|
|
19
|
+
const RuleTypeDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
20
|
+
tableName: tableName,
|
|
21
|
+
columns: "deleted_at",
|
|
22
|
+
where: "deleted_at IS NOT NULL",
|
|
23
|
+
});
|
|
24
|
+
const RuleTypeRuleAttributeIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
|
25
|
+
tableName: tableName,
|
|
26
|
+
columns: "rule_attribute",
|
|
27
|
+
where: "deleted_at IS NULL",
|
|
28
|
+
});
|
|
18
29
|
let RuleType = class RuleType {
|
|
19
30
|
constructor() {
|
|
20
31
|
this.price_sets = new core_1.Collection(this);
|
|
32
|
+
this.deleted_at = null;
|
|
21
33
|
}
|
|
22
34
|
onCreate() {
|
|
23
35
|
this.id = (0, utils_1.generateEntityId)(this.id, "rul-typ");
|
|
@@ -35,7 +47,8 @@ __decorate([
|
|
|
35
47
|
__metadata("design:type", String)
|
|
36
48
|
], RuleType.prototype, "name", void 0);
|
|
37
49
|
__decorate([
|
|
38
|
-
|
|
50
|
+
RuleTypeRuleAttributeIndex.MikroORMIndex(),
|
|
51
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
39
52
|
__metadata("design:type", String)
|
|
40
53
|
], RuleType.prototype, "rule_attribute", void 0);
|
|
41
54
|
__decorate([
|
|
@@ -63,6 +76,11 @@ __decorate([
|
|
|
63
76
|
}),
|
|
64
77
|
__metadata("design:type", Date)
|
|
65
78
|
], RuleType.prototype, "updated_at", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
RuleTypeDeletedAtIndex.MikroORMIndex(),
|
|
81
|
+
(0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], RuleType.prototype, "deleted_at", void 0);
|
|
66
84
|
__decorate([
|
|
67
85
|
(0, core_1.BeforeCreate)(),
|
|
68
86
|
__metadata("design:type", Function),
|
|
@@ -76,6 +94,7 @@ __decorate([
|
|
|
76
94
|
__metadata("design:returntype", void 0)
|
|
77
95
|
], RuleType.prototype, "onInit", null);
|
|
78
96
|
RuleType = __decorate([
|
|
79
|
-
(0, core_1.Entity)()
|
|
97
|
+
(0, core_1.Entity)({ tableName }),
|
|
98
|
+
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
|
80
99
|
], RuleType);
|
|
81
100
|
exports.default = RuleType;
|
|
@@ -33,22 +33,25 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
|
33
33
|
const date = new Date().toISOString();
|
|
34
34
|
// Gets all the price set money amounts where rules match for each of the contexts
|
|
35
35
|
// that the price set is configured for
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const priceSubQueryKnex = knex({
|
|
37
|
+
price: "price",
|
|
38
38
|
})
|
|
39
39
|
.select({
|
|
40
|
-
id: "
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
id: "price1.id",
|
|
41
|
+
amount: "price1.amount",
|
|
42
|
+
min_quantity: "price1.min_quantity",
|
|
43
|
+
max_quantity: "price1.max_quantity",
|
|
44
|
+
currency_code: "price1.currency_code",
|
|
45
|
+
price_set_id: "price1.price_set_id",
|
|
46
|
+
rules_count: "price1.rules_count",
|
|
47
|
+
price_list_id: "price1.price_list_id",
|
|
45
48
|
pl_rules_count: "pl.rules_count",
|
|
46
49
|
pl_type: "pl.type",
|
|
47
|
-
has_price_list: knex.raw("case when
|
|
50
|
+
has_price_list: knex.raw("case when price1.price_list_id IS NULL then False else True end"),
|
|
48
51
|
})
|
|
49
|
-
.leftJoin("
|
|
50
|
-
.leftJoin("price_rule as pr", "pr.
|
|
51
|
-
.leftJoin("price_list as pl", "pl.id", "
|
|
52
|
+
.leftJoin("price as price1", "price1.id", "price1.id")
|
|
53
|
+
.leftJoin("price_rule as pr", "pr.price_id", "price1.id")
|
|
54
|
+
.leftJoin("price_list as pl", "pl.id", "price1.price_list_id")
|
|
52
55
|
.leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
|
|
53
56
|
.leftJoin("price_list_rule_value as plrv", "plrv.price_list_rule_id", "plr.id")
|
|
54
57
|
.leftJoin("rule_type as plrt", "plrt.id", "plr.rule_type_id")
|
|
@@ -57,21 +60,21 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
|
57
60
|
{ column: "rules_count", order: "desc" },
|
|
58
61
|
{ column: "pl.rules_count", order: "desc" },
|
|
59
62
|
])
|
|
60
|
-
.groupBy("
|
|
61
|
-
.having(knex.raw("count(DISTINCT rt.rule_attribute) =
|
|
62
|
-
.orHaving(knex.raw("count(DISTINCT plrt.rule_attribute) = pl.rules_count AND
|
|
63
|
-
|
|
63
|
+
.groupBy("price1.id", "pl.id")
|
|
64
|
+
.having(knex.raw("count(DISTINCT rt.rule_attribute) = price1.rules_count AND price1.price_list_id IS NULL"))
|
|
65
|
+
.orHaving(knex.raw("count(DISTINCT plrt.rule_attribute) = pl.rules_count AND price1.price_list_id IS NOT NULL"));
|
|
66
|
+
priceSubQueryKnex.orWhere((q) => {
|
|
64
67
|
for (const [key, value] of Object.entries(context)) {
|
|
65
68
|
q.orWhere({
|
|
66
69
|
"rt.rule_attribute": key,
|
|
67
70
|
"pr.value": value,
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
|
-
q.orWhere("
|
|
71
|
-
q.whereNull("
|
|
73
|
+
q.orWhere("price1.rules_count", "=", 0);
|
|
74
|
+
q.whereNull("price1.price_list_id");
|
|
72
75
|
});
|
|
73
|
-
|
|
74
|
-
q.whereNotNull("
|
|
76
|
+
priceSubQueryKnex.orWhere((q) => {
|
|
77
|
+
q.whereNotNull("price1.price_list_id")
|
|
75
78
|
.andWhere(function () {
|
|
76
79
|
this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date);
|
|
77
80
|
})
|
|
@@ -96,9 +99,9 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
|
96
99
|
"pr.value": value,
|
|
97
100
|
});
|
|
98
101
|
}
|
|
99
|
-
this.andWhere("
|
|
102
|
+
this.andWhere("price1.rules_count", ">", 0);
|
|
100
103
|
});
|
|
101
|
-
this.orWhere("
|
|
104
|
+
this.orWhere("price1.rules_count", "=", 0);
|
|
102
105
|
});
|
|
103
106
|
});
|
|
104
107
|
});
|
|
@@ -106,37 +109,36 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
|
106
109
|
ps: "price_set",
|
|
107
110
|
})
|
|
108
111
|
.select({
|
|
109
|
-
id: "
|
|
112
|
+
id: "price.id",
|
|
110
113
|
price_set_id: "ps.id",
|
|
111
|
-
amount: "
|
|
112
|
-
min_quantity: "
|
|
113
|
-
max_quantity: "
|
|
114
|
-
currency_code: "
|
|
114
|
+
amount: "price.amount",
|
|
115
|
+
min_quantity: "price.min_quantity",
|
|
116
|
+
max_quantity: "price.max_quantity",
|
|
117
|
+
currency_code: "price.currency_code",
|
|
115
118
|
default_priority: "rt.default_priority",
|
|
116
|
-
rules_count: "
|
|
117
|
-
pl_rules_count: "
|
|
118
|
-
price_list_type: "
|
|
119
|
-
price_list_id: "
|
|
119
|
+
rules_count: "price.rules_count",
|
|
120
|
+
pl_rules_count: "price.pl_rules_count",
|
|
121
|
+
price_list_type: "price.pl_type",
|
|
122
|
+
price_list_id: "price.price_list_id",
|
|
120
123
|
})
|
|
121
|
-
.join(
|
|
122
|
-
.
|
|
123
|
-
.leftJoin("price_rule as pr", "pr.price_set_money_amount_id", "psma.id")
|
|
124
|
+
.join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
|
|
125
|
+
.leftJoin("price_rule as pr", "pr.price_id", "price.id")
|
|
124
126
|
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
|
125
127
|
.whereIn("ps.id", pricingFilters.id)
|
|
126
|
-
.andWhere("
|
|
128
|
+
.andWhere("price.currency_code", "=", currencyCode)
|
|
127
129
|
.orderBy([
|
|
128
|
-
{ column: "
|
|
130
|
+
{ column: "price.has_price_list", order: "asc" },
|
|
129
131
|
{ column: "amount", order: "asc" },
|
|
130
132
|
{ column: "rules_count", order: "desc" },
|
|
131
133
|
{ column: "default_priority", order: "desc" },
|
|
132
134
|
]);
|
|
133
135
|
if (quantity) {
|
|
134
|
-
priceSetQueryKnex.where("
|
|
135
|
-
priceSetQueryKnex.andWhere("
|
|
136
|
+
priceSetQueryKnex.where("price.min_quantity", "<=", quantity);
|
|
137
|
+
priceSetQueryKnex.andWhere("price.max_quantity", ">=", quantity);
|
|
136
138
|
}
|
|
137
139
|
else {
|
|
138
140
|
priceSetQueryKnex.andWhere(function () {
|
|
139
|
-
this.andWhere("
|
|
141
|
+
this.andWhere("price.min_quantity", "<=", "1").orWhereNull("price.min_quantity");
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
144
|
return await priceSetQueryKnex;
|
package/dist/scripts/seed.js
CHANGED
|
@@ -31,8 +31,8 @@ const path_1 = require("path");
|
|
|
31
31
|
async function run({ options, logger, path, }) {
|
|
32
32
|
logger ?? (logger = console);
|
|
33
33
|
logger.info(`Loading seed data from ${path}...`);
|
|
34
|
-
const {
|
|
35
|
-
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData
|
|
34
|
+
const { priceSetsData, pricesData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
|
|
35
|
+
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and pricesData.${os_1.EOL}${e}`);
|
|
36
36
|
throw e;
|
|
37
37
|
});
|
|
38
38
|
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig("pricing", options);
|
|
@@ -41,10 +41,9 @@ async function run({ options, logger, path, }) {
|
|
|
41
41
|
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
|
42
42
|
const manager = orm.em.fork();
|
|
43
43
|
try {
|
|
44
|
-
logger.info("Inserting price_sets &
|
|
45
|
-
await createMoneyAmounts(manager, moneyAmountsData);
|
|
44
|
+
logger.info("Inserting price_sets & prices");
|
|
46
45
|
await createPriceSets(manager, priceSetsData);
|
|
47
|
-
await
|
|
46
|
+
await createPrices(manager, pricesData);
|
|
48
47
|
}
|
|
49
48
|
catch (e) {
|
|
50
49
|
logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
|
|
@@ -52,13 +51,6 @@ async function run({ options, logger, path, }) {
|
|
|
52
51
|
await orm.close(true);
|
|
53
52
|
}
|
|
54
53
|
exports.run = run;
|
|
55
|
-
async function createMoneyAmounts(manager, data) {
|
|
56
|
-
const moneyAmounts = data.map((moneyAmountData) => {
|
|
57
|
-
return manager.create(PricingModels.MoneyAmount, moneyAmountData);
|
|
58
|
-
});
|
|
59
|
-
await manager.persistAndFlush(moneyAmounts);
|
|
60
|
-
return moneyAmounts;
|
|
61
|
-
}
|
|
62
54
|
async function createPriceSets(manager, data) {
|
|
63
55
|
const priceSets = data.map((priceSetData) => {
|
|
64
56
|
return manager.create(PricingModels.PriceSet, priceSetData);
|
|
@@ -66,10 +58,10 @@ async function createPriceSets(manager, data) {
|
|
|
66
58
|
await manager.persistAndFlush(priceSets);
|
|
67
59
|
return priceSets;
|
|
68
60
|
}
|
|
69
|
-
async function
|
|
70
|
-
const
|
|
71
|
-
return manager.create(PricingModels.
|
|
61
|
+
async function createPrices(manager, data) {
|
|
62
|
+
const prices = data.map((priceData) => {
|
|
63
|
+
return manager.create(PricingModels.Price, priceData);
|
|
72
64
|
});
|
|
73
|
-
await manager.persistAndFlush(
|
|
74
|
-
return
|
|
65
|
+
await manager.persistAndFlush(prices);
|
|
66
|
+
return prices;
|
|
75
67
|
}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { default as PriceListService } from "./price-list";
|
|
2
|
-
export { default as PriceListRuleService } from "./price-list-rule";
|
|
3
|
-
export { default as PriceListRuleValueService } from "./price-list-rule-value";
|
|
4
|
-
export { default as PriceRuleService } from "./price-rule";
|
|
5
2
|
export { default as PricingModuleService } from "./pricing-module";
|
|
6
3
|
export { default as RuleTypeService } from "./rule-type";
|
package/dist/services/index.js
CHANGED
|
@@ -3,15 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RuleTypeService = exports.PricingModuleService = exports.
|
|
6
|
+
exports.RuleTypeService = exports.PricingModuleService = exports.PriceListService = void 0;
|
|
7
7
|
var price_list_1 = require("./price-list");
|
|
8
8
|
Object.defineProperty(exports, "PriceListService", { enumerable: true, get: function () { return __importDefault(price_list_1).default; } });
|
|
9
|
-
var price_list_rule_1 = require("./price-list-rule");
|
|
10
|
-
Object.defineProperty(exports, "PriceListRuleService", { enumerable: true, get: function () { return __importDefault(price_list_rule_1).default; } });
|
|
11
|
-
var price_list_rule_value_1 = require("./price-list-rule-value");
|
|
12
|
-
Object.defineProperty(exports, "PriceListRuleValueService", { enumerable: true, get: function () { return __importDefault(price_list_rule_value_1).default; } });
|
|
13
|
-
var price_rule_1 = require("./price-rule");
|
|
14
|
-
Object.defineProperty(exports, "PriceRuleService", { enumerable: true, get: function () { return __importDefault(price_rule_1).default; } });
|
|
15
9
|
var pricing_module_1 = require("./pricing-module");
|
|
16
10
|
Object.defineProperty(exports, "PricingModuleService", { enumerable: true, get: function () { return __importDefault(pricing_module_1).default; } });
|
|
17
11
|
var rule_type_1 = require("./rule-type");
|
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
import { AddPricesDTO, Context, DAL, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, RuleTypeDTO } from "@medusajs/types";
|
|
2
2
|
import { ModulesSdkUtils } from "@medusajs/utils";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Price, PriceList, PriceListRule, PriceListRuleValue, PriceRule, PriceSet, PriceSetRuleType, RuleType } from "../models";
|
|
4
|
+
import { PriceListService, RuleTypeService } from ".";
|
|
5
5
|
type InjectedDependencies = {
|
|
6
6
|
baseRepository: DAL.RepositoryService;
|
|
7
7
|
pricingRepository: PricingRepositoryService;
|
|
8
|
-
moneyAmountService: ModulesSdkTypes.InternalModuleService<any>;
|
|
9
8
|
priceSetService: ModulesSdkTypes.InternalModuleService<any>;
|
|
10
|
-
priceSetMoneyAmountRulesService: ModulesSdkTypes.InternalModuleService<any>;
|
|
11
9
|
ruleTypeService: RuleTypeService<any>;
|
|
12
|
-
priceRuleService:
|
|
10
|
+
priceRuleService: ModulesSdkTypes.InternalModuleService<any>;
|
|
13
11
|
priceSetRuleTypeService: ModulesSdkTypes.InternalModuleService<any>;
|
|
14
|
-
|
|
12
|
+
priceService: ModulesSdkTypes.InternalModuleService<any>;
|
|
15
13
|
priceListService: PriceListService<any>;
|
|
16
|
-
priceListRuleService:
|
|
17
|
-
priceListRuleValueService:
|
|
14
|
+
priceListRuleService: ModulesSdkTypes.InternalModuleService<any>;
|
|
15
|
+
priceListRuleValueService: ModulesSdkTypes.InternalModuleService<any>;
|
|
18
16
|
};
|
|
19
17
|
declare const PricingModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, PriceSetDTO, {
|
|
20
|
-
|
|
21
|
-
dto: PricingTypes.
|
|
22
|
-
};
|
|
23
|
-
PriceSetMoneyAmount: {
|
|
24
|
-
dto: PricingTypes.PriceSetMoneyAmountDTO;
|
|
25
|
-
};
|
|
26
|
-
PriceSetMoneyAmountRules: {
|
|
27
|
-
dto: PricingTypes.PriceSetMoneyAmountRulesDTO;
|
|
18
|
+
Price: {
|
|
19
|
+
dto: PricingTypes.PriceDTO;
|
|
28
20
|
};
|
|
29
21
|
PriceRule: {
|
|
30
22
|
dto: PricingTypes.PriceRuleDTO;
|
|
23
|
+
create: PricingTypes.CreatePriceRuleDTO;
|
|
24
|
+
update: PricingTypes.UpdatePriceRuleDTO;
|
|
31
25
|
};
|
|
32
26
|
RuleType: {
|
|
33
27
|
dto: PricingTypes.RuleTypeDTO;
|
|
28
|
+
create: PricingTypes.CreateRuleTypeDTO;
|
|
29
|
+
update: PricingTypes.UpdateRuleTypeDTO;
|
|
34
30
|
};
|
|
35
31
|
PriceList: {
|
|
36
32
|
dto: PricingTypes.PriceListDTO;
|
|
@@ -39,21 +35,19 @@ declare const PricingModuleService_base: new (container: InjectedDependencies) =
|
|
|
39
35
|
dto: PricingTypes.PriceListRuleDTO;
|
|
40
36
|
};
|
|
41
37
|
}>;
|
|
42
|
-
export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet,
|
|
38
|
+
export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet, TRuleType extends RuleType = RuleType, TPriceRule extends PriceRule = PriceRule, TPriceSetRuleType extends PriceSetRuleType = PriceSetRuleType, TPrice extends Price = Price, TPriceList extends PriceList = PriceList, TPriceListRule extends PriceListRule = PriceListRule, TPriceListRuleValue extends PriceListRuleValue = PriceListRuleValue> extends PricingModuleService_base implements PricingTypes.IPricingModuleService {
|
|
43
39
|
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
44
40
|
protected baseRepository_: DAL.RepositoryService;
|
|
45
41
|
protected readonly pricingRepository_: PricingRepositoryService;
|
|
46
|
-
protected readonly moneyAmountService_: ModulesSdkTypes.InternalModuleService<TMoneyAmount>;
|
|
47
42
|
protected readonly ruleTypeService_: RuleTypeService<TRuleType>;
|
|
48
43
|
protected readonly priceSetService_: ModulesSdkTypes.InternalModuleService<TPriceSet>;
|
|
49
|
-
protected readonly
|
|
50
|
-
protected readonly priceRuleService_: PriceRuleService<TPriceRule>;
|
|
44
|
+
protected readonly priceRuleService_: ModulesSdkTypes.InternalModuleService<TPriceRule>;
|
|
51
45
|
protected readonly priceSetRuleTypeService_: ModulesSdkTypes.InternalModuleService<TPriceSetRuleType>;
|
|
52
|
-
protected readonly
|
|
46
|
+
protected readonly priceService_: ModulesSdkTypes.InternalModuleService<TPrice>;
|
|
53
47
|
protected readonly priceListService_: PriceListService<TPriceList>;
|
|
54
|
-
protected readonly priceListRuleService_:
|
|
55
|
-
protected readonly priceListRuleValueService_:
|
|
56
|
-
constructor({ baseRepository, pricingRepository,
|
|
48
|
+
protected readonly priceListRuleService_: ModulesSdkTypes.InternalModuleService<TPriceListRule>;
|
|
49
|
+
protected readonly priceListRuleValueService_: ModulesSdkTypes.InternalModuleService<TPriceListRuleValue>;
|
|
50
|
+
constructor({ baseRepository, pricingRepository, ruleTypeService, priceSetService, priceRuleService, priceSetRuleTypeService, priceService, priceListService, priceListRuleService, priceListRuleValueService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
57
51
|
__joinerConfig(): ModuleJoinerConfig;
|
|
58
52
|
calculatePrices(pricingFilters: PricingFilters, pricingContext?: PricingContext, sharedContext?: Context): Promise<PricingTypes.CalculatedPriceSet[]>;
|
|
59
53
|
create(data: PricingTypes.CreatePriceSetDTO, sharedContext?: Context): Promise<PriceSetDTO>;
|
|
@@ -67,16 +61,8 @@ export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet,
|
|
|
67
61
|
protected addPrices_(input: AddPricesDTO[], sharedContext?: Context): Promise<void>;
|
|
68
62
|
removeRules(data: PricingTypes.RemovePriceSetRulesDTO[], sharedContext?: Context): Promise<void>;
|
|
69
63
|
update(data: PricingTypes.UpdatePriceSetDTO[], sharedContext?: Context): Promise<PriceSetDTO[]>;
|
|
70
|
-
createMoneyAmounts(data: PricingTypes.CreateMoneyAmountDTO[], sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO[]>;
|
|
71
|
-
updateMoneyAmounts(data: PricingTypes.UpdateMoneyAmountDTO[], sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO[]>;
|
|
72
|
-
createRuleTypes(data: PricingTypes.CreateRuleTypeDTO[], sharedContext?: Context): Promise<PricingTypes.RuleTypeDTO[]>;
|
|
73
|
-
updateRuleTypes(data: PricingTypes.UpdateRuleTypeDTO[], sharedContext?: Context): Promise<PricingTypes.RuleTypeDTO[]>;
|
|
74
|
-
createPriceSetMoneyAmountRules(data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[], sharedContext?: Context): Promise<PricingTypes.PriceSetMoneyAmountRulesDTO[]>;
|
|
75
|
-
updatePriceSetMoneyAmountRules(data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[], sharedContext?: Context): Promise<PricingTypes.PriceSetMoneyAmountRulesDTO[]>;
|
|
76
|
-
createPriceRules(data: PricingTypes.CreatePriceRuleDTO[], sharedContext?: Context): Promise<PricingTypes.PriceRuleDTO[]>;
|
|
77
|
-
updatePriceRules(data: PricingTypes.UpdatePriceRuleDTO[], sharedContext?: Context): Promise<PricingTypes.PriceRuleDTO[]>;
|
|
78
64
|
createPriceLists(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListDTO[]>;
|
|
79
|
-
protected createPriceLists_(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<
|
|
65
|
+
protected createPriceLists_(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<TPriceList[]>;
|
|
80
66
|
updatePriceLists(data: PricingTypes.UpdatePriceListDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListDTO[]>;
|
|
81
67
|
protected updatePriceLists_(data: PricingTypes.UpdatePriceListDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListDTO[]>;
|
|
82
68
|
createPriceListRules(data: PricingTypes.CreatePriceListRuleDTO[], sharedContext?: Context): Promise<PricingTypes.PriceListRuleDTO[]>;
|