@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.
@@ -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, _models_1.RuleType],
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,4 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20240626133555 extends Migration {
3
+ up(): Promise<void>;
4
+ }
@@ -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;
@@ -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";
@@ -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.RuleType = exports.PriceSetRuleType = exports.PriceSet = exports.PriceRule = exports.PriceListRuleValue = exports.PriceListRule = exports.PriceList = exports.Price = void 0;
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 { Collection, OptionalProps, Rel } from "@mikro-orm/core";
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
- rule_type_id: string;
11
- rule_type: Rel<RuleType>;
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.price_list_rule_values = new core_1.Collection(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
- PriceListRuleRuleTypeIdIndex.MikroORMIndex(),
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, "rule_type_id", void 0);
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.OneToMany)(() => price_list_rule_value_1.default, (plrv) => plrv.price_list_rule, {
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, "price_list_rule_values", void 0);
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
- price_set_id: string;
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", "rule_type_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
- PriceRulePriceSetIdIndex.MikroORMIndex(),
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, "rule_type_id", void 0);
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;
@@ -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: "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",
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 price1.price_list_id IS NULL then False else True end"),
50
+ has_price_list: knex.raw("case when price.price_list_id IS NULL then False else True end"),
51
51
  })
52
- .leftJoin("price as price1", "price1.id", "price1.id")
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", "price1.price_list_id").andOn("pl.status", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]));
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("price1.id", "pl.id")
66
- .having(knex.raw("count(DISTINCT rt.rule_attribute) = price1.rules_count AND price1.price_list_id IS NULL"))
67
- .orHaving(knex.raw("count(DISTINCT plrt.rule_attribute) = pl.rules_count AND price1.price_list_id IS NOT NULL"));
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
- "rt.rule_attribute": key,
67
+ "pr.attribute": key,
72
68
  "pr.value": value,
73
69
  });
74
70
  }
75
- q.orWhere("price1.rules_count", "=", 0);
76
- q.whereNull("price1.price_list_id");
71
+ q.orWhere("price.rules_count", "=", 0);
72
+ q.whereNull("price.price_list_id");
77
73
  });
78
74
  priceSubQueryKnex.orWhere((q) => {
79
- q.whereNotNull("price1.price_list_id")
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
- "plrt.rule_attribute": key,
86
+ "plr.attribute": key,
91
87
  });
92
- this.whereIn("plrv.value", [value]);
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
- "rt.rule_attribute": key,
96
+ "pr.attribute": key,
101
97
  "pr.value": value,
102
98
  });
103
99
  }
104
- this.andWhere("price1.rules_count", ">", 0);
100
+ this.andWhere("price.rules_count", ">", 0);
105
101
  });
106
- this.orWhere("price1.rules_count", "=", 0);
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);
@@ -1,3 +1 @@
1
- export { default as PriceListService } from "./price-list";
2
1
  export { default as PricingModuleService } from "./pricing-module";
3
- export { default as RuleTypeService } from "./rule-type";
@@ -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.RuleTypeService = exports.PricingModuleService = exports.PriceListService = void 0;
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, RuleTypeDTO, UpsertPriceSetDTO } from "@medusajs/types";
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, PriceListRuleValue, PriceRule, PriceSet } from "../models";
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: 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_: PriceListService;
41
+ protected readonly priceListService_: ModulesSdkTypes.IMedusaInternalService<PriceList>;
51
42
  protected readonly priceListRuleService_: ModulesSdkTypes.IMedusaInternalService<PriceListRule>;
52
- protected readonly priceListRuleValueService_: ModulesSdkTypes.IMedusaInternalService<PriceListRuleValue>;
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<PricingTypes.PriceListDTO[]>;
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 {};