@medusajs/pricing 0.1.13-snapshot-20240531102054 → 0.1.13-snapshot-20240701122250

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. package/dist/index.d.ts +2 -3
  2. package/dist/index.js +7 -4
  3. package/dist/joiner-config.d.ts +1 -8
  4. package/dist/joiner-config.js +10 -52
  5. package/dist/migrations/Migration20240626133555.d.ts +4 -0
  6. package/dist/migrations/Migration20240626133555.js +33 -0
  7. package/dist/models/index.d.ts +0 -3
  8. package/dist/models/index.js +1 -7
  9. package/dist/models/price-list-rule.d.ts +4 -7
  10. package/dist/models/price-list-rule.js +6 -27
  11. package/dist/models/price-list.d.ts +0 -2
  12. package/dist/models/price-list.js +0 -9
  13. package/dist/models/price-rule.d.ts +3 -8
  14. package/dist/models/price-rule.js +4 -43
  15. package/dist/models/price-set.d.ts +0 -4
  16. package/dist/models/price-set.js +0 -19
  17. package/dist/models/price.d.ts +3 -3
  18. package/dist/models/price.js +1 -1
  19. package/dist/repositories/pricing.js +25 -30
  20. package/dist/services/index.d.ts +0 -2
  21. package/dist/services/index.js +1 -5
  22. package/dist/services/pricing-module.d.ts +38 -52
  23. package/dist/services/pricing-module.js +405 -509
  24. package/dist/types/services/price-list.d.ts +9 -9
  25. package/dist/utils/events.d.ts +38 -0
  26. package/dist/utils/events.js +42 -0
  27. package/dist/utils/index.d.ts +1 -0
  28. package/dist/utils/index.js +1 -0
  29. package/package.json +7 -10
  30. package/dist/models/price-list-rule-value.d.ts +0 -17
  31. package/dist/models/price-list-rule-value.js +0 -102
  32. package/dist/models/price-set-rule-type.d.ts +0 -10
  33. package/dist/models/price-set-rule-type.js +0 -108
  34. package/dist/models/rule-type.d.ts +0 -17
  35. package/dist/models/rule-type.js +0 -100
  36. package/dist/module-definition.d.ts +0 -2
  37. package/dist/module-definition.js +0 -8
  38. package/dist/scripts/bin/run-seed.d.ts +0 -3
  39. package/dist/scripts/bin/run-seed.js +0 -38
  40. package/dist/scripts/seed.d.ts +0 -4
  41. package/dist/scripts/seed.js +0 -67
  42. package/dist/services/price-list.d.ts +0 -16
  43. package/dist/services/price-list.js +0 -34
  44. package/dist/services/rule-type.d.ts +0 -15
  45. package/dist/services/rule-type.js +0 -53
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { moduleDefinition } from "./module-definition";
1
+ import { ModuleExports } from "@medusajs/types";
2
+ export declare const moduleDefinition: ModuleExports;
2
3
  export default moduleDefinition;
3
- export * from "./models";
4
- export * from "./services";
5
4
  export * from "./types";
package/dist/index.js CHANGED
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- const module_definition_1 = require("./module-definition");
18
- exports.default = module_definition_1.moduleDefinition;
19
- __exportStar(require("./models"), exports);
20
- __exportStar(require("./services"), exports);
17
+ exports.moduleDefinition = void 0;
18
+ const _services_1 = require("./services");
19
+ const service = _services_1.PricingModuleService;
20
+ exports.moduleDefinition = {
21
+ service,
22
+ };
23
+ exports.default = exports.moduleDefinition;
21
24
  __exportStar(require("./types"), exports);
@@ -1,10 +1,3 @@
1
- import { ModuleJoinerConfig } from "@medusajs/types";
2
1
  import { MapToConfig } from "@medusajs/utils";
3
- export declare const LinkableKeys: {
4
- price_set_id: string;
5
- price_list_id: string;
6
- price_id: string;
7
- rule_type_id: string;
8
- };
2
+ export declare const joinerConfig: Omit<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys"> & Required<Pick<import("@medusajs/types").ModuleJoinerConfig, "serviceName" | "primaryKeys" | "alias" | "linkableKeys">>;
9
3
  export declare const entityNameToLinkableKeysMap: MapToConfig;
10
- export declare const joinerConfig: ModuleJoinerConfig;
@@ -1,56 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
7
- const modules_sdk_1 = require("@medusajs/modules-sdk");
3
+ exports.entityNameToLinkableKeysMap = exports.joinerConfig = void 0;
4
+ const utils_1 = require("@medusajs/utils");
8
5
  const _models_1 = require("./models");
9
- const schema_1 = __importDefault(require("./schema"));
10
- exports.LinkableKeys = {
11
- price_set_id: _models_1.PriceSet.name,
12
- price_list_id: _models_1.PriceList.name,
13
- price_id: _models_1.Price.name,
14
- rule_type_id: _models_1.RuleType.name,
15
- };
16
- const entityLinkableKeysMap = {};
17
- Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
18
- entityLinkableKeysMap[value] ??= [];
19
- entityLinkableKeysMap[value].push({
20
- mapTo: key,
21
- valueFrom: key.split("_").pop(),
22
- });
6
+ exports.joinerConfig = (0, utils_1.defineJoinerConfig)(utils_1.Modules.PRICING, {
7
+ entityQueryingConfig: [_models_1.PriceSet, _models_1.PriceList, _models_1.Price],
8
+ linkableKeys: {
9
+ price_set_id: _models_1.PriceSet.name,
10
+ price_list_id: _models_1.PriceList.name,
11
+ price_id: _models_1.Price.name,
12
+ },
23
13
  });
24
- exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
25
- exports.joinerConfig = {
26
- serviceName: modules_sdk_1.Modules.PRICING,
27
- primaryKeys: ["id"],
28
- linkableKeys: exports.LinkableKeys,
29
- schema: schema_1.default,
30
- alias: [
31
- {
32
- name: ["price_set", "price_sets"],
33
- args: {
34
- entity: "PriceSet",
35
- },
36
- },
37
- {
38
- name: ["price_list", "price_lists"],
39
- args: {
40
- methodSuffix: "PriceLists",
41
- },
42
- },
43
- {
44
- name: ["price", "prices"],
45
- args: {
46
- methodSuffix: "Prices",
47
- },
48
- },
49
- {
50
- name: ["rule_type", "rule_types"],
51
- args: {
52
- methodSuffix: "RuleTypes",
53
- },
54
- },
55
- ],
56
- };
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,17 +1,14 @@
1
1
  import { DAL } from "@medusajs/types";
2
- import { Collection, OptionalProps } 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: RuleType;
12
- price_list_rule_values: Collection<PriceListRuleValue, object>;
8
+ attribute: string;
9
+ value: string | string[] | null;
13
10
  price_list_id: string;
14
- price_list: PriceList;
11
+ price_list: Rel<PriceList>;
15
12
  created_at: Date;
16
13
  updated_at: Date;
17
14
  deleted_at: Date | null;
@@ -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", rule_type_1.default)
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, {
@@ -85,7 +64,7 @@ __decorate([
85
64
  ], PriceListRule.prototype, "price_list_id", void 0);
86
65
  __decorate([
87
66
  (0, core_1.ManyToOne)(() => price_list_1.default, { persist: false }),
88
- __metadata("design:type", price_list_1.default)
67
+ __metadata("design:type", Object)
89
68
  ], PriceListRule.prototype, "price_list", void 0);
90
69
  __decorate([
91
70
  (0, core_1.Property)({
@@ -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,20 +1,15 @@
1
1
  import { DAL } from "@medusajs/types";
2
- import { OptionalProps } from "@mikro-orm/core";
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: PriceSet;
12
- rule_type_id: string;
13
- rule_type: RuleType;
8
+ attribute: string;
14
9
  value: string;
15
10
  priority: number;
16
11
  price_id: string;
17
- price: Price;
12
+ price: Rel<Price>;
18
13
  created_at: Date;
19
14
  updated_at: Date;
20
15
  deleted_at: Date | null;
@@ -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", price_set_1.default)
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", rule_type_1.default)
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)
@@ -108,7 +69,7 @@ __decorate([
108
69
  ], PriceRule.prototype, "price_id", void 0);
109
70
  __decorate([
110
71
  (0, core_1.ManyToOne)(() => price_1.default, { persist: false }),
111
- __metadata("design:type", price_1.default)
72
+ __metadata("design:type", Object)
112
73
  ], PriceRule.prototype, "price", void 0);
113
74
  __decorate([
114
75
  (0, core_1.Property)({
@@ -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(),
@@ -1,6 +1,6 @@
1
1
  import { DAL } from "@medusajs/types";
2
2
  import { BigNumber } from "@medusajs/utils";
3
- import { Collection, OptionalProps } from "@mikro-orm/core";
3
+ import { Collection, OptionalProps, Rel } from "@mikro-orm/core";
4
4
  import PriceList from "./price-list";
5
5
  import PriceRule from "./price-rule";
6
6
  import PriceSet from "./price-set";
@@ -15,11 +15,11 @@ export default class Price {
15
15
  min_quantity: number | null;
16
16
  max_quantity: number | null;
17
17
  price_set_id: string;
18
- price_set?: PriceSet;
18
+ price_set?: Rel<PriceSet>;
19
19
  rules_count: number;
20
20
  price_rules: Collection<PriceRule, object>;
21
21
  price_list_id: string | null;
22
- price_list: PriceList | null;
22
+ price_list: Rel<PriceList> | null;
23
23
  created_at: Date;
24
24
  updated_at: Date;
25
25
  deleted_at: Date | null;
@@ -101,7 +101,7 @@ __decorate([
101
101
  ], Price.prototype, "price_set_id", void 0);
102
102
  __decorate([
103
103
  (0, core_1.ManyToOne)(() => price_set_1.default, { persist: false }),
104
- __metadata("design:type", price_set_1.default)
104
+ __metadata("design:type", Object)
105
105
  ], Price.prototype, "price_set", void 0);
106
106
  __decorate([
107
107
  (0, core_1.Property)({ columnType: "integer", default: 0 }),
@@ -37,44 +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
+ })
52
+ .leftJoin("price_rule as pr", "pr.price_id", "price.id")
53
+ .leftJoin("price_list as pl", function () {
54
+ this.on("pl.id", "price.price_list_id").andOn("pl.status", knex.raw("?", [utils_1.PriceListStatus.ACTIVE]));
51
55
  })
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")
55
56
  .leftJoin("price_list_rule as plr", "plr.price_list_id", "pl.id")
56
- .leftJoin("price_list_rule_value as plrv", "plrv.price_list_rule_id", "plr.id")
57
- .leftJoin("rule_type as plrt", "plrt.id", "plr.rule_type_id")
58
- .leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
59
57
  .orderBy([
60
58
  { column: "rules_count", order: "desc" },
61
59
  { column: "pl.rules_count", order: "desc" },
62
60
  ])
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"));
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"));
66
64
  priceSubQueryKnex.orWhere((q) => {
67
65
  for (const [key, value] of Object.entries(context)) {
68
66
  q.orWhere({
69
- "rt.rule_attribute": key,
67
+ "pr.attribute": key,
70
68
  "pr.value": value,
71
69
  });
72
70
  }
73
- q.orWhere("price1.rules_count", "=", 0);
74
- q.whereNull("price1.price_list_id");
71
+ q.orWhere("price.rules_count", "=", 0);
72
+ q.whereNull("price.price_list_id");
75
73
  });
76
74
  priceSubQueryKnex.orWhere((q) => {
77
- q.whereNotNull("price1.price_list_id")
75
+ q.whereNotNull("price.price_list_id")
78
76
  .andWhere(function () {
79
77
  this.whereNull("pl.starts_at").orWhere("pl.starts_at", "<=", date);
80
78
  })
@@ -85,9 +83,9 @@ class PricingRepository extends utils_1.MikroOrmBase {
85
83
  this.andWhere(function () {
86
84
  for (const [key, value] of Object.entries(context)) {
87
85
  this.orWhere({
88
- "plrt.rule_attribute": key,
86
+ "plr.attribute": key,
89
87
  });
90
- this.whereIn("plrv.value", [value]);
88
+ this.where("plr.value", "@>", JSON.stringify(Array.isArray(value) ? value : [value]));
91
89
  }
92
90
  this.orWhere("pl.rules_count", "=", 0);
93
91
  });
@@ -95,13 +93,13 @@ class PricingRepository extends utils_1.MikroOrmBase {
95
93
  this.andWhere(function () {
96
94
  for (const [key, value] of Object.entries(context)) {
97
95
  this.orWhere({
98
- "rt.rule_attribute": key,
96
+ "pr.attribute": key,
99
97
  "pr.value": value,
100
98
  });
101
99
  }
102
- this.andWhere("price1.rules_count", ">", 0);
100
+ this.andWhere("price.rules_count", ">", 0);
103
101
  });
104
- this.orWhere("price1.rules_count", "=", 0);
102
+ this.orWhere("price.rules_count", "=", 0);
105
103
  });
106
104
  });
107
105
  });
@@ -115,7 +113,6 @@ class PricingRepository extends utils_1.MikroOrmBase {
115
113
  min_quantity: "price.min_quantity",
116
114
  max_quantity: "price.max_quantity",
117
115
  currency_code: "price.currency_code",
118
- default_priority: "rt.default_priority",
119
116
  rules_count: "price.rules_count",
120
117
  pl_rules_count: "price.pl_rules_count",
121
118
  price_list_type: "price.pl_type",
@@ -123,14 +120,12 @@ class PricingRepository extends utils_1.MikroOrmBase {
123
120
  })
124
121
  .join(priceSubQueryKnex.as("price"), "price.price_set_id", "ps.id")
125
122
  .leftJoin("price_rule as pr", "pr.price_id", "price.id")
126
- .leftJoin("rule_type as rt", "rt.id", "pr.rule_type_id")
127
123
  .whereIn("ps.id", pricingFilters.id)
128
124
  .andWhere("price.currency_code", "=", currencyCode)
129
125
  .orderBy([
130
126
  { column: "price.has_price_list", order: "asc" },
131
127
  { column: "amount", order: "asc" },
132
128
  { column: "rules_count", order: "desc" },
133
- { column: "default_priority", order: "desc" },
134
129
  ]);
135
130
  if (quantity) {
136
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";