@medusajs/pricing 0.1.13-preview-20240701060617 → 0.1.13-preview-20240701074916
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/joiner-config.js +1 -2
- package/dist/migrations/Migration20240626133555.d.ts +4 -0
- package/dist/migrations/Migration20240626133555.js +33 -0
- package/dist/models/index.d.ts +0 -3
- package/dist/models/index.js +1 -7
- package/dist/models/price-list-rule.d.ts +3 -6
- package/dist/models/price-list-rule.js +5 -26
- package/dist/models/price-list.d.ts +0 -2
- package/dist/models/price-list.js +0 -9
- package/dist/models/price-rule.d.ts +1 -6
- package/dist/models/price-rule.js +3 -42
- package/dist/models/price-set.d.ts +0 -4
- package/dist/models/price-set.js +0 -19
- package/dist/repositories/pricing.js +23 -30
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +1 -5
- package/dist/services/pricing-module.d.ts +8 -17
- package/dist/services/pricing-module.js +217 -286
- package/dist/types/services/price-list.d.ts +8 -9
- package/dist/utils/events.d.ts +0 -6
- package/dist/utils/events.js +0 -6
- package/package.json +5 -5
- package/dist/models/price-list-rule-value.d.ts +0 -17
- package/dist/models/price-list-rule-value.js +0 -102
- package/dist/models/price-set-rule-type.d.ts +0 -10
- package/dist/models/price-set-rule-type.js +0 -108
- package/dist/models/rule-type.d.ts +0 -17
- package/dist/models/rule-type.js +0 -100
- package/dist/services/price-list.d.ts +0 -16
- package/dist/services/price-list.js +0 -34
- package/dist/services/rule-type.d.ts +0 -15
- package/dist/services/rule-type.js +0 -53
package/dist/joiner-config.js
CHANGED
@@ -4,12 +4,11 @@ exports.entityNameToLinkableKeysMap = exports.joinerConfig = void 0;
|
|
4
4
|
const utils_1 = require("@medusajs/utils");
|
5
5
|
const _models_1 = require("./models");
|
6
6
|
exports.joinerConfig = (0, utils_1.defineJoinerConfig)(utils_1.Modules.PRICING, {
|
7
|
-
entityQueryingConfig: [_models_1.PriceSet, _models_1.PriceList, _models_1.Price
|
7
|
+
entityQueryingConfig: [_models_1.PriceSet, _models_1.PriceList, _models_1.Price],
|
8
8
|
linkableKeys: {
|
9
9
|
price_set_id: _models_1.PriceSet.name,
|
10
10
|
price_list_id: _models_1.PriceList.name,
|
11
11
|
price_id: _models_1.Price.name,
|
12
|
-
rule_type_id: _models_1.RuleType.name,
|
13
12
|
},
|
14
13
|
});
|
15
14
|
exports.entityNameToLinkableKeysMap = (0, utils_1.buildEntitiesNameToLinkableKeysMap)(exports.joinerConfig.linkableKeys);
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Migration20240626133555 = void 0;
|
4
|
+
const migrations_1 = require("@mikro-orm/migrations");
|
5
|
+
class Migration20240626133555 extends migrations_1.Migration {
|
6
|
+
async up() {
|
7
|
+
this.addSql('alter table if exists "price_list_rule" add column if not exists "value" jsonb;');
|
8
|
+
// TODO: Added on 28.06.2024, Drop defaults after a while.
|
9
|
+
this.addSql('alter table if exists "price_list_rule" add column if not exists "attribute" text not null DEFAULT \'\';');
|
10
|
+
this.addSql('alter table if exists "price_rule" add column if not exists "attribute" text not null DEFAULT \'\';');
|
11
|
+
/* DATA MIGRATION */
|
12
|
+
this.addSql("update price_rule set attribute = (SELECT rule_attribute FROM rule_type WHERE rule_type.id = price_rule.rule_type_id);");
|
13
|
+
this.addSql("update price_list_rule set value = (SELECT array_to_json(ARRAY(SELECT value FROM price_list_rule_value WHERE price_list_rule_value.price_list_rule_id = price_list_rule.id))::jsonb);");
|
14
|
+
this.addSql("update price_list_rule set attribute = (SELECT rule_attribute FROM rule_type WHERE rule_type.id = price_list_rule.rule_type_id);");
|
15
|
+
/* DATA MIGRATION END */
|
16
|
+
this.addSql('alter table if exists "price_set_rule_type" drop constraint if exists "price_set_rule_type_rule_type_id_foreign";');
|
17
|
+
this.addSql('alter table if exists "price_rule" drop constraint if exists "price_rule_rule_type_id_foreign";');
|
18
|
+
this.addSql('alter table if exists "price_list_rule" drop constraint if exists "price_list_rule_rule_type_id_foreign";');
|
19
|
+
this.addSql('alter table if exists "price_rule" drop constraint if exists "price_rule_price_set_id_foreign";');
|
20
|
+
this.addSql('drop index if exists "IDX_price_list_rule_rule_type_id_unique";');
|
21
|
+
this.addSql('drop index if exists "IDX_price_rule_price_set_id";');
|
22
|
+
this.addSql('drop index if exists "IDX_price_rule_rule_type_id";');
|
23
|
+
this.addSql('drop index if exists "IDX_price_rule_price_id_unique";');
|
24
|
+
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_price_rule_price_id_attribute_unique" ON "price_rule" (price_id, attribute) WHERE deleted_at IS NULL;');
|
25
|
+
this.addSql('alter table if exists "price_rule" drop column if exists "price_set_id";');
|
26
|
+
this.addSql('alter table if exists "price_rule" drop column if exists "rule_type_id";');
|
27
|
+
this.addSql('alter table if exists "price_list_rule" drop column if exists "rule_type_id";');
|
28
|
+
this.addSql('drop table if exists "rule_type" cascade;');
|
29
|
+
this.addSql('drop table if exists "price_set_rule_type" cascade;');
|
30
|
+
this.addSql('drop table if exists "price_list_rule_value" cascade;');
|
31
|
+
}
|
32
|
+
}
|
33
|
+
exports.Migration20240626133555 = Migration20240626133555;
|
package/dist/models/index.d.ts
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
export { default as Price } from "./price";
|
2
2
|
export { default as PriceList } from "./price-list";
|
3
3
|
export { default as PriceListRule } from "./price-list-rule";
|
4
|
-
export { default as PriceListRuleValue } from "./price-list-rule-value";
|
5
4
|
export { default as PriceRule } from "./price-rule";
|
6
5
|
export { default as PriceSet } from "./price-set";
|
7
|
-
export { default as PriceSetRuleType } from "./price-set-rule-type";
|
8
|
-
export { default as RuleType } from "./rule-type";
|
package/dist/models/index.js
CHANGED
@@ -3,20 +3,14 @@ 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.
|
6
|
+
exports.PriceSet = exports.PriceRule = exports.PriceListRule = exports.PriceList = exports.Price = void 0;
|
7
7
|
var price_1 = require("./price");
|
8
8
|
Object.defineProperty(exports, "Price", { enumerable: true, get: function () { return __importDefault(price_1).default; } });
|
9
9
|
var price_list_1 = require("./price-list");
|
10
10
|
Object.defineProperty(exports, "PriceList", { enumerable: true, get: function () { return __importDefault(price_list_1).default; } });
|
11
11
|
var price_list_rule_1 = require("./price-list-rule");
|
12
12
|
Object.defineProperty(exports, "PriceListRule", { enumerable: true, get: function () { return __importDefault(price_list_rule_1).default; } });
|
13
|
-
var price_list_rule_value_1 = require("./price-list-rule-value");
|
14
|
-
Object.defineProperty(exports, "PriceListRuleValue", { enumerable: true, get: function () { return __importDefault(price_list_rule_value_1).default; } });
|
15
13
|
var price_rule_1 = require("./price-rule");
|
16
14
|
Object.defineProperty(exports, "PriceRule", { enumerable: true, get: function () { return __importDefault(price_rule_1).default; } });
|
17
15
|
var price_set_1 = require("./price-set");
|
18
16
|
Object.defineProperty(exports, "PriceSet", { enumerable: true, get: function () { return __importDefault(price_set_1).default; } });
|
19
|
-
var price_set_rule_type_1 = require("./price-set-rule-type");
|
20
|
-
Object.defineProperty(exports, "PriceSetRuleType", { enumerable: true, get: function () { return __importDefault(price_set_rule_type_1).default; } });
|
21
|
-
var rule_type_1 = require("./rule-type");
|
22
|
-
Object.defineProperty(exports, "RuleType", { enumerable: true, get: function () { return __importDefault(rule_type_1).default; } });
|
@@ -1,15 +1,12 @@
|
|
1
1
|
import { DAL } from "@medusajs/types";
|
2
|
-
import {
|
2
|
+
import { OptionalProps, Rel } from "@mikro-orm/core";
|
3
3
|
import PriceList from "./price-list";
|
4
|
-
import PriceListRuleValue from "./price-list-rule-value";
|
5
|
-
import RuleType from "./rule-type";
|
6
4
|
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
7
5
|
export default class PriceListRule {
|
8
6
|
[OptionalProps]: OptionalFields;
|
9
7
|
id: string;
|
10
|
-
|
11
|
-
|
12
|
-
price_list_rule_values: Collection<PriceListRuleValue, object>;
|
8
|
+
attribute: string;
|
9
|
+
value: string | string[] | null;
|
13
10
|
price_list_id: string;
|
14
11
|
price_list: Rel<PriceList>;
|
15
12
|
created_at: Date;
|
@@ -15,20 +15,12 @@ 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_list_1 = __importDefault(require("./price-list"));
|
18
|
-
const price_list_rule_value_1 = __importDefault(require("./price-list-rule-value"));
|
19
|
-
const rule_type_1 = __importDefault(require("./rule-type"));
|
20
18
|
const tableName = "price_list_rule";
|
21
19
|
const PriceListRuleDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
22
20
|
tableName: tableName,
|
23
21
|
columns: "deleted_at",
|
24
22
|
where: "deleted_at IS NOT NULL",
|
25
23
|
});
|
26
|
-
const PriceListRuleRuleTypeIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
27
|
-
tableName: tableName,
|
28
|
-
columns: "rule_type_id",
|
29
|
-
where: "deleted_at IS NULL",
|
30
|
-
unique: true,
|
31
|
-
});
|
32
24
|
const PriceListRulePriceListIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
33
25
|
tableName: tableName,
|
34
26
|
columns: "price_list_id",
|
@@ -36,18 +28,16 @@ const PriceListRulePriceListIdIndex = (0, utils_1.createPsqlIndexStatementHelper
|
|
36
28
|
});
|
37
29
|
let PriceListRule = class PriceListRule {
|
38
30
|
constructor() {
|
39
|
-
this.
|
31
|
+
this.value = null;
|
40
32
|
this.deleted_at = null;
|
41
33
|
}
|
42
34
|
beforeCreate() {
|
43
35
|
this.id = (0, utils_1.generateEntityId)(this.id, "plrule");
|
44
36
|
this.price_list_id ??= this.price_list?.id;
|
45
|
-
this.rule_type_id ??= this.rule_type?.id;
|
46
37
|
}
|
47
38
|
onInit() {
|
48
39
|
this.id = (0, utils_1.generateEntityId)(this.id, "plrule");
|
49
40
|
this.price_list_id ??= this.price_list?.id;
|
50
|
-
this.rule_type_id ??= this.rule_type?.id;
|
51
41
|
}
|
52
42
|
};
|
53
43
|
__decorate([
|
@@ -55,24 +45,13 @@ __decorate([
|
|
55
45
|
__metadata("design:type", String)
|
56
46
|
], PriceListRule.prototype, "id", void 0);
|
57
47
|
__decorate([
|
58
|
-
|
59
|
-
(0, core_1.ManyToOne)(() => rule_type_1.default, {
|
60
|
-
columnType: "text",
|
61
|
-
mapToPk: true,
|
62
|
-
fieldName: "rule_type_id",
|
63
|
-
}),
|
48
|
+
(0, core_1.Property)({ columnType: "text" }),
|
64
49
|
__metadata("design:type", String)
|
65
|
-
], PriceListRule.prototype, "
|
66
|
-
__decorate([
|
67
|
-
(0, core_1.ManyToOne)(() => rule_type_1.default, { persist: false }),
|
68
|
-
__metadata("design:type", Object)
|
69
|
-
], PriceListRule.prototype, "rule_type", void 0);
|
50
|
+
], PriceListRule.prototype, "attribute", void 0);
|
70
51
|
__decorate([
|
71
|
-
(0, core_1.
|
72
|
-
cascade: [core_1.Cascade.PERSIST, "soft-remove"],
|
73
|
-
}),
|
52
|
+
(0, core_1.Property)({ columnType: "jsonb", nullable: true }),
|
74
53
|
__metadata("design:type", Object)
|
75
|
-
], PriceListRule.prototype, "
|
54
|
+
], PriceListRule.prototype, "value", void 0);
|
76
55
|
__decorate([
|
77
56
|
PriceListRulePriceListIdIndex.MikroORMIndex(),
|
78
57
|
(0, core_1.ManyToOne)(() => price_list_1.default, {
|
@@ -3,7 +3,6 @@ import { PriceListStatus, PriceListType } from "@medusajs/utils";
|
|
3
3
|
import { Collection, OptionalProps } from "@mikro-orm/core";
|
4
4
|
import Price from "./price";
|
5
5
|
import PriceListRule from "./price-list-rule";
|
6
|
-
import RuleType from "./rule-type";
|
7
6
|
type OptionalFields = "starts_at" | "ends_at" | DAL.SoftDeletableEntityDateColumns;
|
8
7
|
export declare const PriceListIdPrefix = "plist";
|
9
8
|
export default class PriceList {
|
@@ -17,7 +16,6 @@ export default class PriceList {
|
|
17
16
|
ends_at: Date | null;
|
18
17
|
prices: Collection<Price, object>;
|
19
18
|
price_list_rules: Collection<PriceListRule, object>;
|
20
|
-
rule_types: Collection<RuleType, object>;
|
21
19
|
rules_count: number;
|
22
20
|
created_at: Date;
|
23
21
|
updated_at: Date;
|
@@ -17,7 +17,6 @@ const utils_1 = require("@medusajs/utils");
|
|
17
17
|
const core_1 = require("@mikro-orm/core");
|
18
18
|
const price_1 = __importDefault(require("./price"));
|
19
19
|
const price_list_rule_1 = __importDefault(require("./price-list-rule"));
|
20
|
-
const rule_type_1 = __importDefault(require("./rule-type"));
|
21
20
|
const tableName = "price_list";
|
22
21
|
const PriceListDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
23
22
|
tableName: tableName,
|
@@ -31,7 +30,6 @@ let PriceList = class PriceList {
|
|
31
30
|
this.ends_at = null;
|
32
31
|
this.prices = new core_1.Collection(this);
|
33
32
|
this.price_list_rules = new core_1.Collection(this);
|
34
|
-
this.rule_types = new core_1.Collection(this);
|
35
33
|
this.rules_count = 0;
|
36
34
|
this.deleted_at = null;
|
37
35
|
}
|
@@ -90,13 +88,6 @@ __decorate([
|
|
90
88
|
}),
|
91
89
|
__metadata("design:type", Object)
|
92
90
|
], PriceList.prototype, "price_list_rules", void 0);
|
93
|
-
__decorate([
|
94
|
-
(0, core_1.ManyToMany)({
|
95
|
-
entity: () => rule_type_1.default,
|
96
|
-
pivotEntity: () => price_list_rule_1.default,
|
97
|
-
}),
|
98
|
-
__metadata("design:type", Object)
|
99
|
-
], PriceList.prototype, "rule_types", void 0);
|
100
91
|
__decorate([
|
101
92
|
(0, core_1.Property)({ columnType: "integer", default: 0 }),
|
102
93
|
__metadata("design:type", Number)
|
@@ -1,16 +1,11 @@
|
|
1
1
|
import { DAL } from "@medusajs/types";
|
2
2
|
import { OptionalProps, Rel } from "@mikro-orm/core";
|
3
3
|
import Price from "./price";
|
4
|
-
import PriceSet from "./price-set";
|
5
|
-
import RuleType from "./rule-type";
|
6
4
|
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
7
5
|
export default class PriceRule {
|
8
6
|
[OptionalProps]?: OptionalFields;
|
9
7
|
id: string;
|
10
|
-
|
11
|
-
price_set: Rel<PriceSet>;
|
12
|
-
rule_type_id: string;
|
13
|
-
rule_type: Rel<RuleType>;
|
8
|
+
attribute: string;
|
14
9
|
value: string;
|
15
10
|
priority: number;
|
16
11
|
price_id: string;
|
@@ -15,27 +15,15 @@ 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_1 = __importDefault(require("./price"));
|
18
|
-
const price_set_1 = __importDefault(require("./price-set"));
|
19
|
-
const rule_type_1 = __importDefault(require("./rule-type"));
|
20
18
|
const tableName = "price_rule";
|
21
19
|
const PriceRuleDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
22
20
|
tableName: tableName,
|
23
21
|
columns: "deleted_at",
|
24
22
|
where: "deleted_at IS NOT NULL",
|
25
23
|
});
|
26
|
-
const PriceRulePriceSetIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
27
|
-
tableName: tableName,
|
28
|
-
columns: "price_set_id",
|
29
|
-
where: "deleted_at IS NULL",
|
30
|
-
});
|
31
|
-
const PriceRuleRuleTypeIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
32
|
-
tableName: tableName,
|
33
|
-
columns: "rule_type_id",
|
34
|
-
where: "deleted_at IS NULL",
|
35
|
-
});
|
36
24
|
const PriceRulePriceIdIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
37
25
|
tableName: tableName,
|
38
|
-
columns: ["price_id", "
|
26
|
+
columns: ["price_id", "attribute"],
|
39
27
|
where: "deleted_at IS NULL",
|
40
28
|
unique: true,
|
41
29
|
});
|
@@ -46,14 +34,10 @@ let PriceRule = class PriceRule {
|
|
46
34
|
}
|
47
35
|
beforeCreate() {
|
48
36
|
this.id = (0, utils_1.generateEntityId)(this.id, "prule");
|
49
|
-
this.rule_type_id ??= this.rule_type?.id;
|
50
|
-
this.price_set_id ??= this.price_set?.id;
|
51
37
|
this.price_id ??= this.price?.id;
|
52
38
|
}
|
53
39
|
onInit() {
|
54
40
|
this.id = (0, utils_1.generateEntityId)(this.id, "prule");
|
55
|
-
this.rule_type_id ??= this.rule_type?.id;
|
56
|
-
this.price_set_id ??= this.price_set?.id;
|
57
41
|
this.price_id ??= this.price?.id;
|
58
42
|
}
|
59
43
|
};
|
@@ -62,32 +46,9 @@ __decorate([
|
|
62
46
|
__metadata("design:type", String)
|
63
47
|
], PriceRule.prototype, "id", void 0);
|
64
48
|
__decorate([
|
65
|
-
|
66
|
-
(0, core_1.ManyToOne)(() => price_set_1.default, {
|
67
|
-
columnType: "text",
|
68
|
-
mapToPk: true,
|
69
|
-
fieldName: "price_set_id",
|
70
|
-
onDelete: "cascade",
|
71
|
-
}),
|
72
|
-
__metadata("design:type", String)
|
73
|
-
], PriceRule.prototype, "price_set_id", void 0);
|
74
|
-
__decorate([
|
75
|
-
(0, core_1.ManyToOne)(() => price_set_1.default, { persist: false }),
|
76
|
-
__metadata("design:type", Object)
|
77
|
-
], PriceRule.prototype, "price_set", void 0);
|
78
|
-
__decorate([
|
79
|
-
PriceRuleRuleTypeIdIndex.MikroORMIndex(),
|
80
|
-
(0, core_1.ManyToOne)(() => rule_type_1.default, {
|
81
|
-
columnType: "text",
|
82
|
-
mapToPk: true,
|
83
|
-
fieldName: "rule_type_id",
|
84
|
-
}),
|
49
|
+
(0, core_1.Property)({ columnType: "text" }),
|
85
50
|
__metadata("design:type", String)
|
86
|
-
], PriceRule.prototype, "
|
87
|
-
__decorate([
|
88
|
-
(0, core_1.ManyToOne)(() => rule_type_1.default, { persist: false }),
|
89
|
-
__metadata("design:type", Object)
|
90
|
-
], PriceRule.prototype, "rule_type", void 0);
|
51
|
+
], PriceRule.prototype, "attribute", void 0);
|
91
52
|
__decorate([
|
92
53
|
(0, core_1.Property)({ columnType: "text" }),
|
93
54
|
__metadata("design:type", String)
|
@@ -1,13 +1,9 @@
|
|
1
1
|
import { Collection } from "@mikro-orm/core";
|
2
2
|
import Price from "./price";
|
3
|
-
import PriceRule from "./price-rule";
|
4
|
-
import RuleType from "./rule-type";
|
5
3
|
export declare const PriceSetIdPrefix = "pset";
|
6
4
|
export default class PriceSet {
|
7
5
|
id: string;
|
8
6
|
prices: Collection<Price, object>;
|
9
|
-
price_rules: Collection<PriceRule, object>;
|
10
|
-
rule_types: Collection<RuleType, object>;
|
11
7
|
created_at: Date;
|
12
8
|
updated_at: Date;
|
13
9
|
deleted_at: Date | null;
|
package/dist/models/price-set.js
CHANGED
@@ -16,9 +16,6 @@ exports.PriceSetIdPrefix = void 0;
|
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
17
17
|
const core_1 = require("@mikro-orm/core");
|
18
18
|
const price_1 = __importDefault(require("./price"));
|
19
|
-
const price_rule_1 = __importDefault(require("./price-rule"));
|
20
|
-
const price_set_rule_type_1 = __importDefault(require("./price-set-rule-type"));
|
21
|
-
const rule_type_1 = __importDefault(require("./rule-type"));
|
22
19
|
const tableName = "price_set";
|
23
20
|
const PriceSetDeletedAtIndex = (0, utils_1.createPsqlIndexStatementHelper)({
|
24
21
|
tableName: tableName,
|
@@ -29,8 +26,6 @@ exports.PriceSetIdPrefix = "pset";
|
|
29
26
|
let PriceSet = class PriceSet {
|
30
27
|
constructor() {
|
31
28
|
this.prices = new core_1.Collection(this);
|
32
|
-
this.price_rules = new core_1.Collection(this);
|
33
|
-
this.rule_types = new core_1.Collection(this);
|
34
29
|
this.deleted_at = null;
|
35
30
|
}
|
36
31
|
onCreate() {
|
@@ -50,20 +45,6 @@ __decorate([
|
|
50
45
|
}),
|
51
46
|
__metadata("design:type", Object)
|
52
47
|
], PriceSet.prototype, "prices", void 0);
|
53
|
-
__decorate([
|
54
|
-
(0, core_1.OneToMany)(() => price_rule_1.default, (pr) => pr.price_set, {
|
55
|
-
cascade: [core_1.Cascade.PERSIST, "soft-remove"],
|
56
|
-
}),
|
57
|
-
__metadata("design:type", Object)
|
58
|
-
], PriceSet.prototype, "price_rules", void 0);
|
59
|
-
__decorate([
|
60
|
-
(0, core_1.ManyToMany)({
|
61
|
-
entity: () => rule_type_1.default,
|
62
|
-
pivotEntity: () => price_set_rule_type_1.default,
|
63
|
-
cascade: ["soft-remove"],
|
64
|
-
}),
|
65
|
-
__metadata("design:type", Object)
|
66
|
-
], PriceSet.prototype, "rule_types", void 0);
|
67
48
|
__decorate([
|
68
49
|
(0, core_1.Property)({
|
69
50
|
onCreate: () => new Date(),
|
@@ -37,46 +37,42 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
37
37
|
price: "price",
|
38
38
|
})
|
39
39
|
.select({
|
40
|
-
id: "
|
41
|
-
amount: "
|
42
|
-
min_quantity: "
|
43
|
-
max_quantity: "
|
44
|
-
currency_code: "
|
45
|
-
price_set_id: "
|
46
|
-
rules_count: "
|
47
|
-
price_list_id: "
|
40
|
+
id: "price.id",
|
41
|
+
amount: "price.amount",
|
42
|
+
min_quantity: "price.min_quantity",
|
43
|
+
max_quantity: "price.max_quantity",
|
44
|
+
currency_code: "price.currency_code",
|
45
|
+
price_set_id: "price.price_set_id",
|
46
|
+
rules_count: "price.rules_count",
|
47
|
+
price_list_id: "price.price_list_id",
|
48
48
|
pl_rules_count: "pl.rules_count",
|
49
49
|
pl_type: "pl.type",
|
50
|
-
has_price_list: knex.raw("case when
|
50
|
+
has_price_list: knex.raw("case when price.price_list_id IS NULL then False else True end"),
|
51
51
|
})
|
52
|
-
.leftJoin("
|
53
|
-
.leftJoin("price_rule as pr", "pr.price_id", "price1.id")
|
52
|
+
.leftJoin("price_rule as pr", "pr.price_id", "price.id")
|
54
53
|
.leftJoin("price_list as pl", function () {
|
55
|
-
this.on("pl.id", "
|
54
|
+
this.on("pl.id", "price.price_list_id").andOn("pl.status", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]));
|
56
55
|
})
|
57
56
|
.leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
|
58
|
-
.leftJoin("price_list_rule_value as plrv", "plrv.price_list_rule_id", "plr.id")
|
59
|
-
.leftJoin("rule_type as plrt", "plrt.id", "plr.rule_type_id")
|
60
|
-
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
61
57
|
.orderBy([
|
62
58
|
{ column: "rules_count", order: "desc" },
|
63
59
|
{ column: "pl.rules_count", order: "desc" },
|
64
60
|
])
|
65
|
-
.groupBy("
|
66
|
-
.having(knex.raw("count(DISTINCT
|
67
|
-
.orHaving(knex.raw("count(DISTINCT
|
61
|
+
.groupBy("price.id", "pl.id")
|
62
|
+
.having(knex.raw("count(DISTINCT pr.attribute) = price.rules_count AND price.price_list_id IS NULL"))
|
63
|
+
.orHaving(knex.raw("count(DISTINCT plr.attribute) = pl.rules_count AND price.price_list_id IS NOT NULL"));
|
68
64
|
priceSubQueryKnex.orWhere((q) => {
|
69
65
|
for (const [key, value] of Object.entries(context)) {
|
70
66
|
q.orWhere({
|
71
|
-
"
|
67
|
+
"pr.attribute": key,
|
72
68
|
"pr.value": value,
|
73
69
|
});
|
74
70
|
}
|
75
|
-
q.orWhere("
|
76
|
-
q.whereNull("
|
71
|
+
q.orWhere("price.rules_count", "=", 0);
|
72
|
+
q.whereNull("price.price_list_id");
|
77
73
|
});
|
78
74
|
priceSubQueryKnex.orWhere((q) => {
|
79
|
-
q.whereNotNull("
|
75
|
+
q.whereNotNull("price.price_list_id")
|
80
76
|
.andWhere(function () {
|
81
77
|
this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date);
|
82
78
|
})
|
@@ -87,9 +83,9 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
87
83
|
this.andWhere(function () {
|
88
84
|
for (const [key, value] of Object.entries(context)) {
|
89
85
|
this.orWhere({
|
90
|
-
"
|
86
|
+
"plr.attribute": key,
|
91
87
|
});
|
92
|
-
this.
|
88
|
+
this.where("plr.value", "@>", JSON.stringify(Array.isArray(value) ? value : [value]));
|
93
89
|
}
|
94
90
|
this.orWhere("pl.rules_count", "=", 0);
|
95
91
|
});
|
@@ -97,13 +93,13 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
97
93
|
this.andWhere(function () {
|
98
94
|
for (const [key, value] of Object.entries(context)) {
|
99
95
|
this.orWhere({
|
100
|
-
"
|
96
|
+
"pr.attribute": key,
|
101
97
|
"pr.value": value,
|
102
98
|
});
|
103
99
|
}
|
104
|
-
this.andWhere("
|
100
|
+
this.andWhere("price.rules_count", ">", 0);
|
105
101
|
});
|
106
|
-
this.orWhere("
|
102
|
+
this.orWhere("price.rules_count", "=", 0);
|
107
103
|
});
|
108
104
|
});
|
109
105
|
});
|
@@ -117,7 +113,6 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
117
113
|
min_quantity: "price.min_quantity",
|
118
114
|
max_quantity: "price.max_quantity",
|
119
115
|
currency_code: "price.currency_code",
|
120
|
-
default_priority: "rt.default_priority",
|
121
116
|
rules_count: "price.rules_count",
|
122
117
|
pl_rules_count: "price.pl_rules_count",
|
123
118
|
price_list_type: "price.pl_type",
|
@@ -125,14 +120,12 @@ class PricingRepository extends utils_1.MikroOrmBase {
|
|
125
120
|
})
|
126
121
|
.join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
|
127
122
|
.leftJoin("price_rule as pr", "pr.price_id", "price.id")
|
128
|
-
.leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
|
129
123
|
.whereIn("ps.id", pricingFilters.id)
|
130
124
|
.andWhere("price.currency_code", "=", currencyCode)
|
131
125
|
.orderBy([
|
132
126
|
{ column: "price.has_price_list", order: "asc" },
|
133
127
|
{ column: "amount", order: "asc" },
|
134
128
|
{ column: "rules_count", order: "desc" },
|
135
|
-
{ column: "default_priority", order: "desc" },
|
136
129
|
]);
|
137
130
|
if (quantity) {
|
138
131
|
priceSetQueryKnex.where("price.min_quantity", "<=", quantity);
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
@@ -3,10 +3,6 @@ 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.
|
7
|
-
var price_list_1 = require("./price-list");
|
8
|
-
Object.defineProperty(exports, "PriceListService", { enumerable: true, get: function () { return __importDefault(price_list_1).default; } });
|
6
|
+
exports.PricingModuleService = void 0;
|
9
7
|
var pricing_module_1 = require("./pricing-module");
|
10
8
|
Object.defineProperty(exports, "PricingModuleService", { enumerable: true, get: function () { return __importDefault(pricing_module_1).default; } });
|
11
|
-
var rule_type_1 = require("./rule-type");
|
12
|
-
Object.defineProperty(exports, "RuleTypeService", { enumerable: true, get: function () { return __importDefault(rule_type_1).default; } });
|
@@ -1,19 +1,16 @@
|
|
1
|
-
import { AddPricesDTO, Context, CreatePriceRuleDTO, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes,
|
1
|
+
import { AddPricesDTO, Context, CreatePriceRuleDTO, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, ModulesSdkTypes, PriceDTO, PriceSetDTO, PricingContext, PricingFilters, PricingRepositoryService, PricingTypes, UpsertPriceSetDTO } from "@medusajs/types";
|
2
2
|
import { ModulesSdkUtils } from "@medusajs/utils";
|
3
|
-
import { Price, PriceList, PriceListRule,
|
4
|
-
import { PriceListService, RuleTypeService } from ".";
|
3
|
+
import { Price, PriceList, PriceListRule, PriceRule, PriceSet } from "../models";
|
5
4
|
import { ServiceTypes } from "../types";
|
5
|
+
import { CreatePriceListDTO } from "src/types/services";
|
6
6
|
type InjectedDependencies = {
|
7
7
|
baseRepository: DAL.RepositoryService;
|
8
8
|
pricingRepository: PricingRepositoryService;
|
9
9
|
priceSetService: ModulesSdkTypes.IMedusaInternalService<any>;
|
10
|
-
ruleTypeService: RuleTypeService;
|
11
10
|
priceRuleService: ModulesSdkTypes.IMedusaInternalService<any>;
|
12
|
-
priceSetRuleTypeService: ModulesSdkTypes.IMedusaInternalService<any>;
|
13
11
|
priceService: ModulesSdkTypes.IMedusaInternalService<any>;
|
14
|
-
priceListService:
|
12
|
+
priceListService: ModulesSdkTypes.IMedusaInternalService<any>;
|
15
13
|
priceListRuleService: ModulesSdkTypes.IMedusaInternalService<any>;
|
16
|
-
priceListRuleValueService: ModulesSdkTypes.IMedusaInternalService<any>;
|
17
14
|
};
|
18
15
|
declare const PricingModuleService_base: new (...args: any[]) => ModulesSdkUtils.AbstractModuleService<{
|
19
16
|
PriceSet: {
|
@@ -27,11 +24,6 @@ declare const PricingModuleService_base: new (...args: any[]) => ModulesSdkUtils
|
|
27
24
|
create: PricingTypes.CreatePriceRuleDTO;
|
28
25
|
update: PricingTypes.UpdatePriceRuleDTO;
|
29
26
|
};
|
30
|
-
RuleType: {
|
31
|
-
dto: PricingTypes.RuleTypeDTO;
|
32
|
-
create: PricingTypes.CreateRuleTypeDTO;
|
33
|
-
update: PricingTypes.UpdateRuleTypeDTO;
|
34
|
-
};
|
35
27
|
PriceList: {
|
36
28
|
dto: PricingTypes.PriceListDTO;
|
37
29
|
};
|
@@ -43,14 +35,12 @@ export default class PricingModuleService extends PricingModuleService_base impl
|
|
43
35
|
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
44
36
|
protected baseRepository_: DAL.RepositoryService;
|
45
37
|
protected readonly pricingRepository_: PricingRepositoryService;
|
46
|
-
protected readonly ruleTypeService_: RuleTypeService;
|
47
38
|
protected readonly priceSetService_: ModulesSdkTypes.IMedusaInternalService<PriceSet>;
|
48
39
|
protected readonly priceRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceRule>;
|
49
40
|
protected readonly priceService_: ModulesSdkTypes.IMedusaInternalService<Price>;
|
50
|
-
protected readonly priceListService_:
|
41
|
+
protected readonly priceListService_: ModulesSdkTypes.IMedusaInternalService<PriceList>;
|
51
42
|
protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceListRule>;
|
52
|
-
|
53
|
-
constructor({ baseRepository, pricingRepository, ruleTypeService, priceSetService, priceRuleService, priceService, priceListService, priceListRuleService, priceListRuleValueService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
43
|
+
constructor({ baseRepository, pricingRepository, priceSetService, priceRuleService, priceService, priceListService, priceListRuleService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
54
44
|
__joinerConfig(): ModuleJoinerConfig;
|
55
45
|
private setupCalculatedPriceConfig_;
|
56
46
|
listPriceSets(filters?: PricingTypes.FilterablePriceSetProps, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<PriceSetDTO[]>;
|
@@ -76,11 +66,12 @@ export default class PricingModuleService extends PricingModuleService_base impl
|
|
76
66
|
protected createPriceSets_(data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context): Promise<PriceSet[]>;
|
77
67
|
protected addPrices_(input: AddPricesDTO[], sharedContext?: Context): Promise<Price[]>;
|
78
68
|
protected createPriceLists_(data: PricingTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<PriceList[]>;
|
79
|
-
protected updatePriceLists_(data: PricingTypes.UpdatePriceListDTO[], sharedContext?: Context): Promise<
|
69
|
+
protected updatePriceLists_(data: PricingTypes.UpdatePriceListDTO[], sharedContext?: Context): Promise<PriceList[]>;
|
80
70
|
protected updatePriceListPrices_(data: PricingTypes.UpdatePriceListPricesDTO[], sharedContext?: Context): Promise<Price[]>;
|
81
71
|
protected removePrices_(ids: string[], sharedContext?: Context): Promise<void>;
|
82
72
|
protected addPriceListPrices_(data: PricingTypes.AddPriceListPricesDTO[], sharedContext?: Context): Promise<Price[]>;
|
83
73
|
protected setPriceListRules_(data: PricingTypes.SetPriceListRulesDTO[], sharedContext?: Context): Promise<PriceList[]>;
|
84
74
|
protected removePriceListRules_(data: PricingTypes.RemovePriceListRulesDTO[], sharedContext?: Context): Promise<PriceList[]>;
|
75
|
+
protected normalizePriceListDate(data: (ServiceTypes.UpdatePriceListDTO | ServiceTypes.CreatePriceListDTO | CreatePriceListDTO)[]): any[];
|
85
76
|
}
|
86
77
|
export {};
|