@medusajs/pricing 0.0.2 → 0.0.3-next-20230912130318
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/joiner-config.d.ts +2 -1
- package/dist/joiner-config.js +44 -3
- package/dist/loaders/container.js +8 -7
- package/dist/migrations/Migration20230907144224.d.ts +4 -0
- package/dist/migrations/Migration20230907144224.js +17 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +5 -1
- package/dist/models/money-amount.d.ts +3 -0
- package/dist/models/money-amount.js +11 -0
- package/dist/models/price-set-money-amount.d.ts +12 -0
- package/dist/models/price-set-money-amount.js +54 -0
- package/dist/models/price-set.d.ts +7 -0
- package/dist/models/price-set.js +47 -0
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +3 -1
- package/dist/repositories/price-set.d.ts +15 -0
- package/dist/repositories/price-set.js +69 -0
- package/dist/scripts/seed.js +19 -3
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +3 -1
- package/dist/services/price-set.d.ts +17 -0
- package/dist/services/price-set.js +96 -0
- package/dist/services/pricing-module.d.ts +21 -9
- package/dist/services/pricing-module.js +126 -6
- package/package.json +4 -4
- package/dist/migrations/Migration20230830085850.d.ts +0 -4
- package/dist/migrations/Migration20230830085850.js +0 -13
package/dist/joiner-config.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { ModuleJoinerConfig } from "@medusajs/types";
|
|
|
2
2
|
import { MapToConfig } from "@medusajs/utils";
|
|
3
3
|
export declare enum LinkableKeys {
|
|
4
4
|
MONEY_AMOUNT_ID = "money_amount_id",
|
|
5
|
-
CURRENCY_CODE = "currency_code"
|
|
5
|
+
CURRENCY_CODE = "currency_code",
|
|
6
|
+
PRICE_SET_ID = "price_set_id"
|
|
6
7
|
}
|
|
7
8
|
export declare const entityNameToLinkableKeysMap: MapToConfig;
|
|
8
9
|
export declare const joinerConfig: ModuleJoinerConfig;
|
package/dist/joiner-config.js
CHANGED
|
@@ -1,16 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
|
|
4
27
|
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
-
const
|
|
28
|
+
const Models = __importStar(require("./models"));
|
|
6
29
|
var LinkableKeys;
|
|
7
30
|
(function (LinkableKeys) {
|
|
8
31
|
LinkableKeys["MONEY_AMOUNT_ID"] = "money_amount_id";
|
|
9
32
|
LinkableKeys["CURRENCY_CODE"] = "currency_code";
|
|
33
|
+
LinkableKeys["PRICE_SET_ID"] = "price_set_id";
|
|
10
34
|
})(LinkableKeys || (exports.LinkableKeys = LinkableKeys = {}));
|
|
11
35
|
exports.entityNameToLinkableKeysMap = {
|
|
12
|
-
[
|
|
13
|
-
|
|
36
|
+
[Models.PriceSet.name]: [
|
|
37
|
+
{ mapTo: LinkableKeys.PRICE_SET_ID, valueFrom: "id" },
|
|
38
|
+
],
|
|
39
|
+
[Models.Currency.name]: [
|
|
40
|
+
{ mapTo: LinkableKeys.CURRENCY_CODE, valueFrom: "code" },
|
|
41
|
+
],
|
|
42
|
+
[Models.MoneyAmount.name]: [
|
|
14
43
|
{ mapTo: LinkableKeys.MONEY_AMOUNT_ID, valueFrom: "id" },
|
|
15
44
|
],
|
|
16
45
|
};
|
|
@@ -19,11 +48,23 @@ exports.joinerConfig = {
|
|
|
19
48
|
primaryKeys: ["id", "currency_code"],
|
|
20
49
|
linkableKeys: Object.values(LinkableKeys),
|
|
21
50
|
alias: [
|
|
51
|
+
{
|
|
52
|
+
name: "price_set",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "price_sets",
|
|
56
|
+
},
|
|
22
57
|
{
|
|
23
58
|
name: "money_amount",
|
|
59
|
+
args: {
|
|
60
|
+
methodSuffix: "MoneyAmounts",
|
|
61
|
+
},
|
|
24
62
|
},
|
|
25
63
|
{
|
|
26
64
|
name: "money_amounts",
|
|
65
|
+
args: {
|
|
66
|
+
methodSuffix: "MoneyAmounts",
|
|
67
|
+
},
|
|
27
68
|
},
|
|
28
69
|
{
|
|
29
70
|
name: "currency",
|
|
@@ -24,15 +24,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const defaultRepositories = __importStar(require("../repositories"));
|
|
27
|
-
const
|
|
28
|
-
const _services_1 = require("../services");
|
|
27
|
+
const defaultServices = __importStar(require("../services"));
|
|
29
28
|
const utils_1 = require("@medusajs/utils");
|
|
30
29
|
const awilix_1 = require("awilix");
|
|
31
30
|
exports.default = async ({ container, options, }) => {
|
|
32
31
|
const customRepositories = options?.repositories;
|
|
33
32
|
container.register({
|
|
34
|
-
currencyService: (0, awilix_1.asClass)(
|
|
35
|
-
moneyAmountService: (0, awilix_1.asClass)(
|
|
33
|
+
currencyService: (0, awilix_1.asClass)(defaultServices.CurrencyService).singleton(),
|
|
34
|
+
moneyAmountService: (0, awilix_1.asClass)(defaultServices.MoneyAmountService).singleton(),
|
|
35
|
+
priceSetService: (0, awilix_1.asClass)(defaultServices.PriceSetService).singleton(),
|
|
36
36
|
});
|
|
37
37
|
if (customRepositories) {
|
|
38
38
|
(0, utils_1.loadCustomRepositories)({
|
|
@@ -47,8 +47,9 @@ exports.default = async ({ container, options, }) => {
|
|
|
47
47
|
};
|
|
48
48
|
function loadDefaultRepositories({ container }) {
|
|
49
49
|
container.register({
|
|
50
|
-
baseRepository: (0, awilix_1.asClass)(
|
|
51
|
-
currencyRepository: (0, awilix_1.asClass)(
|
|
52
|
-
moneyAmountRepository: (0, awilix_1.asClass)(
|
|
50
|
+
baseRepository: (0, awilix_1.asClass)(defaultRepositories.BaseRepository).singleton(),
|
|
51
|
+
currencyRepository: (0, awilix_1.asClass)(defaultRepositories.CurrencyRepository).singleton(),
|
|
52
|
+
moneyAmountRepository: (0, awilix_1.asClass)(defaultRepositories.MoneyAmountRepository).singleton(),
|
|
53
|
+
priceSetRepository: (0, awilix_1.asClass)(defaultRepositories.PriceSetRepository).singleton(),
|
|
53
54
|
});
|
|
54
55
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20230907144224 = void 0;
|
|
4
|
+
const migrations_1 = require("@mikro-orm/migrations");
|
|
5
|
+
class Migration20230907144224 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql('create table "currency" ("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null, constraint "currency_pkey" primary key ("code"));');
|
|
8
|
+
this.addSql('create table "money_amount" ("id" text not null, "currency_code" text null, "amount" numeric null, "min_quantity" numeric null, "max_quantity" numeric null, constraint "money_amount_pkey" primary key ("id"));');
|
|
9
|
+
this.addSql('create index "IDX_money_amount_currency_code" on "money_amount" ("currency_code");');
|
|
10
|
+
this.addSql('create table "price_set" ("id" text not null, constraint "price_set_pkey" primary key ("id"));');
|
|
11
|
+
this.addSql('create table "price_set_money_amount" ("id" text not null, "price_set_id" text null, "money_amount_id" text null, "title" text not null, constraint "price_set_money_amount_pkey" primary key ("id", "price_set_id", "money_amount_id"));');
|
|
12
|
+
this.addSql('alter table "money_amount" add constraint "money_amount_currency_code_foreign" foreign key ("currency_code") references "currency" ("code") on update cascade on delete set null;');
|
|
13
|
+
this.addSql('alter table "price_set_money_amount" add constraint "price_set_money_amount_price_set_id_foreign" foreign key ("price_set_id") references "price_set" ("id") on update cascade;');
|
|
14
|
+
this.addSql('alter table "price_set_money_amount" add constraint "price_set_money_amount_money_amount_id_foreign" foreign key ("money_amount_id") references "money_amount" ("id") on update cascade;');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Migration20230907144224 = Migration20230907144224;
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/index.js
CHANGED
|
@@ -3,8 +3,12 @@ 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.MoneyAmount = exports.Currency = void 0;
|
|
6
|
+
exports.PriceSetMoneyAmount = exports.PriceSet = exports.MoneyAmount = exports.Currency = void 0;
|
|
7
7
|
var currency_1 = require("./currency");
|
|
8
8
|
Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return __importDefault(currency_1).default; } });
|
|
9
9
|
var money_amount_1 = require("./money-amount");
|
|
10
10
|
Object.defineProperty(exports, "MoneyAmount", { enumerable: true, get: function () { return __importDefault(money_amount_1).default; } });
|
|
11
|
+
var price_set_1 = require("./price-set");
|
|
12
|
+
Object.defineProperty(exports, "PriceSet", { enumerable: true, get: function () { return __importDefault(price_set_1).default; } });
|
|
13
|
+
var price_set_money_amount_1 = require("./price-set-money-amount");
|
|
14
|
+
Object.defineProperty(exports, "PriceSetMoneyAmount", { enumerable: true, get: function () { return __importDefault(price_set_money_amount_1).default; } });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
|
1
2
|
import Currency from "./currency";
|
|
3
|
+
import PriceSet from "./price-set";
|
|
2
4
|
declare class MoneyAmount {
|
|
3
5
|
id: string;
|
|
4
6
|
currency_code?: string;
|
|
7
|
+
price_sets: Collection<PriceSet, object>;
|
|
5
8
|
currency?: Currency;
|
|
6
9
|
amount?: number;
|
|
7
10
|
min_quantity?: number | null;
|
|
@@ -15,7 +15,11 @@ 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 currency_1 = __importDefault(require("./currency"));
|
|
18
|
+
const price_set_1 = __importDefault(require("./price-set"));
|
|
18
19
|
let MoneyAmount = class MoneyAmount {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.price_sets = new core_1.Collection(this);
|
|
22
|
+
}
|
|
19
23
|
onCreate() {
|
|
20
24
|
this.id = (0, utils_1.generateEntityId)(this.id, "ma");
|
|
21
25
|
}
|
|
@@ -28,6 +32,13 @@ __decorate([
|
|
|
28
32
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
|
29
33
|
__metadata("design:type", String)
|
|
30
34
|
], MoneyAmount.prototype, "currency_code", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, core_1.ManyToMany)({
|
|
37
|
+
entity: () => price_set_1.default,
|
|
38
|
+
mappedBy: (ps) => ps.money_amounts,
|
|
39
|
+
}),
|
|
40
|
+
__metadata("design:type", Object)
|
|
41
|
+
], MoneyAmount.prototype, "price_sets", void 0);
|
|
31
42
|
__decorate([
|
|
32
43
|
(0, core_1.ManyToOne)(() => currency_1.default, {
|
|
33
44
|
nullable: true,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrimaryKeyType } from "@mikro-orm/core";
|
|
2
|
+
import MoneyAmount from "./money-amount";
|
|
3
|
+
import PriceSet from "./price-set";
|
|
4
|
+
export default class PriceSetMoneyAmount {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
price_set?: PriceSet;
|
|
8
|
+
money_amount?: MoneyAmount;
|
|
9
|
+
onCreate(): void;
|
|
10
|
+
[PrimaryKeyType]?: [string, string];
|
|
11
|
+
constructor(money_amount: MoneyAmount, price_set: PriceSet);
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@medusajs/utils");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const money_amount_1 = __importDefault(require("./money-amount"));
|
|
18
|
+
const price_set_1 = __importDefault(require("./price-set"));
|
|
19
|
+
let PriceSetMoneyAmount = class PriceSetMoneyAmount {
|
|
20
|
+
onCreate() {
|
|
21
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "psma");
|
|
22
|
+
}
|
|
23
|
+
constructor(money_amount, price_set) {
|
|
24
|
+
this.money_amount = money_amount;
|
|
25
|
+
this.price_set = price_set;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], PriceSetMoneyAmount.prototype, "id", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, core_1.Property)({ columnType: "text" }),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], PriceSetMoneyAmount.prototype, "title", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, core_1.ManyToOne)(() => price_set_1.default, { onDelete: "cascade" }),
|
|
38
|
+
__metadata("design:type", price_set_1.default)
|
|
39
|
+
], PriceSetMoneyAmount.prototype, "price_set", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, core_1.ManyToOne)(() => money_amount_1.default, {}),
|
|
42
|
+
__metadata("design:type", money_amount_1.default)
|
|
43
|
+
], PriceSetMoneyAmount.prototype, "money_amount", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, core_1.BeforeCreate)(),
|
|
46
|
+
__metadata("design:type", Function),
|
|
47
|
+
__metadata("design:paramtypes", []),
|
|
48
|
+
__metadata("design:returntype", void 0)
|
|
49
|
+
], PriceSetMoneyAmount.prototype, "onCreate", null);
|
|
50
|
+
PriceSetMoneyAmount = __decorate([
|
|
51
|
+
(0, core_1.Entity)(),
|
|
52
|
+
__metadata("design:paramtypes", [money_amount_1.default, price_set_1.default])
|
|
53
|
+
], PriceSetMoneyAmount);
|
|
54
|
+
exports.default = PriceSetMoneyAmount;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const utils_1 = require("@medusajs/utils");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const money_amount_1 = __importDefault(require("./money-amount"));
|
|
18
|
+
const price_set_money_amount_1 = __importDefault(require("./price-set-money-amount"));
|
|
19
|
+
let PriceSet = class PriceSet {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.money_amounts = new core_1.Collection(this);
|
|
22
|
+
}
|
|
23
|
+
onCreate() {
|
|
24
|
+
this.id = (0, utils_1.generateEntityId)(this.id, "pset");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], PriceSet.prototype, "id", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, core_1.ManyToMany)({
|
|
33
|
+
entity: () => money_amount_1.default,
|
|
34
|
+
pivotEntity: () => price_set_money_amount_1.default,
|
|
35
|
+
}),
|
|
36
|
+
__metadata("design:type", Object)
|
|
37
|
+
], PriceSet.prototype, "money_amounts", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, core_1.BeforeCreate)(),
|
|
40
|
+
__metadata("design:type", Function),
|
|
41
|
+
__metadata("design:paramtypes", []),
|
|
42
|
+
__metadata("design:returntype", void 0)
|
|
43
|
+
], PriceSet.prototype, "onCreate", null);
|
|
44
|
+
PriceSet = __decorate([
|
|
45
|
+
(0, core_1.Entity)()
|
|
46
|
+
], PriceSet);
|
|
47
|
+
exports.default = PriceSet;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MoneyAmountRepository = exports.CurrencyRepository = exports.BaseRepository = void 0;
|
|
3
|
+
exports.PriceSetRepository = exports.MoneyAmountRepository = exports.CurrencyRepository = exports.BaseRepository = void 0;
|
|
4
4
|
var utils_1 = require("@medusajs/utils");
|
|
5
5
|
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
|
|
6
6
|
var currency_1 = require("./currency");
|
|
7
7
|
Object.defineProperty(exports, "CurrencyRepository", { enumerable: true, get: function () { return currency_1.CurrencyRepository; } });
|
|
8
8
|
var money_amount_1 = require("./money-amount");
|
|
9
9
|
Object.defineProperty(exports, "MoneyAmountRepository", { enumerable: true, get: function () { return money_amount_1.MoneyAmountRepository; } });
|
|
10
|
+
var price_set_1 = require("./price-set");
|
|
11
|
+
Object.defineProperty(exports, "PriceSetRepository", { enumerable: true, get: function () { return price_set_1.PriceSetRepository; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Context, CreatePriceSetDTO, DAL, UpdatePriceSetDTO } from "@medusajs/types";
|
|
2
|
+
import { DALUtils } from "@medusajs/utils";
|
|
3
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
4
|
+
import { PriceSet } from "../models";
|
|
5
|
+
export declare class PriceSetRepository extends DALUtils.MikroOrmBaseRepository {
|
|
6
|
+
protected readonly manager_: SqlEntityManager;
|
|
7
|
+
constructor({ manager }: {
|
|
8
|
+
manager: SqlEntityManager;
|
|
9
|
+
});
|
|
10
|
+
find(findOptions?: DAL.FindOptions<PriceSet>, context?: Context): Promise<PriceSet[]>;
|
|
11
|
+
findAndCount(findOptions?: DAL.FindOptions<PriceSet>, context?: Context): Promise<[PriceSet[], number]>;
|
|
12
|
+
delete(ids: string[], context?: Context): Promise<void>;
|
|
13
|
+
create(data: CreatePriceSetDTO[], context?: Context): Promise<PriceSet[]>;
|
|
14
|
+
update(data: UpdatePriceSetDTO[], context?: Context): Promise<PriceSet[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PriceSetRepository = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
const core_1 = require("@mikro-orm/core");
|
|
6
|
+
const _models_1 = require("../models");
|
|
7
|
+
class PriceSetRepository extends utils_1.DALUtils.MikroOrmBaseRepository {
|
|
8
|
+
constructor({ manager }) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
// eslint-disable-next-line prefer-rest-params
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.manager_ = manager;
|
|
13
|
+
}
|
|
14
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
15
|
+
const manager = this.getActiveManager(context);
|
|
16
|
+
const findOptions_ = { ...findOptions };
|
|
17
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
18
|
+
Object.assign(findOptions_.options, {
|
|
19
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
20
|
+
});
|
|
21
|
+
return await manager.find(_models_1.PriceSet, findOptions_.where, findOptions_.options);
|
|
22
|
+
}
|
|
23
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
24
|
+
const manager = this.getActiveManager(context);
|
|
25
|
+
const findOptions_ = { ...findOptions };
|
|
26
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
27
|
+
Object.assign(findOptions_.options, {
|
|
28
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
29
|
+
});
|
|
30
|
+
return await manager.findAndCount(_models_1.PriceSet, findOptions_.where, findOptions_.options);
|
|
31
|
+
}
|
|
32
|
+
async delete(ids, context = {}) {
|
|
33
|
+
const manager = this.getActiveManager(context);
|
|
34
|
+
await manager.nativeDelete(_models_1.PriceSet, { id: { $in: ids } }, {});
|
|
35
|
+
}
|
|
36
|
+
async create(data, context = {}) {
|
|
37
|
+
const manager = this.getActiveManager(context);
|
|
38
|
+
const priceSets = data.map((priceSetData) => {
|
|
39
|
+
return manager.create(_models_1.PriceSet, priceSetData);
|
|
40
|
+
});
|
|
41
|
+
manager.persist(priceSets);
|
|
42
|
+
return priceSets;
|
|
43
|
+
}
|
|
44
|
+
async update(data, context = {}) {
|
|
45
|
+
const manager = this.getActiveManager(context);
|
|
46
|
+
const priceSetIds = data.map((priceSetData) => priceSetData.id);
|
|
47
|
+
const existingPriceSets = await this.find({
|
|
48
|
+
where: {
|
|
49
|
+
id: {
|
|
50
|
+
$in: priceSetIds,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}, context);
|
|
54
|
+
const existingPriceSetMap = new Map(existingPriceSets.map((priceSet) => [
|
|
55
|
+
priceSet.id,
|
|
56
|
+
priceSet,
|
|
57
|
+
]));
|
|
58
|
+
const priceSets = data.map((priceSetData) => {
|
|
59
|
+
const existingPriceSet = existingPriceSetMap.get(priceSetData.id);
|
|
60
|
+
if (!existingPriceSet) {
|
|
61
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `PriceSet with id "${priceSetData.id}" not found`);
|
|
62
|
+
}
|
|
63
|
+
return manager.assign(existingPriceSet, priceSetData);
|
|
64
|
+
});
|
|
65
|
+
manager.persist(priceSets);
|
|
66
|
+
return priceSets;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.PriceSetRepository = PriceSetRepository;
|
package/dist/scripts/seed.js
CHANGED
|
@@ -31,8 +31,8 @@ const path_1 = require("path");
|
|
|
31
31
|
async function run({ options, logger, path, }) {
|
|
32
32
|
logger ?? (logger = console);
|
|
33
33
|
logger.info(`Loading seed data from ${path}...`);
|
|
34
|
-
const { currenciesData, moneyAmountsData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
|
|
35
|
-
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: currenciesData, moneyAmountsData.${os_1.EOL}${e}`);
|
|
34
|
+
const { currenciesData, moneyAmountsData, priceSetsData, priceSetMoneyAmountsData, } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
|
|
35
|
+
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData, currenciesData, moneyAmountsData and priceSetMoneyAmountsData.${os_1.EOL}${e}`);
|
|
36
36
|
throw e;
|
|
37
37
|
});
|
|
38
38
|
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig("pricing", options);
|
|
@@ -41,9 +41,11 @@ async function run({ options, logger, path, }) {
|
|
|
41
41
|
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
|
42
42
|
const manager = orm.em.fork();
|
|
43
43
|
try {
|
|
44
|
-
logger.info("Inserting currencies & money_amounts");
|
|
44
|
+
logger.info("Inserting price_sets, currencies & money_amounts");
|
|
45
45
|
await createCurrencies(manager, currenciesData);
|
|
46
46
|
await createMoneyAmounts(manager, moneyAmountsData);
|
|
47
|
+
await createPriceSets(manager, priceSetsData);
|
|
48
|
+
await createPriceSetMoneyAmounts(manager, priceSetMoneyAmountsData);
|
|
47
49
|
}
|
|
48
50
|
catch (e) {
|
|
49
51
|
logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
|
|
@@ -65,3 +67,17 @@ async function createMoneyAmounts(manager, data) {
|
|
|
65
67
|
await manager.persistAndFlush(moneyAmounts);
|
|
66
68
|
return moneyAmounts;
|
|
67
69
|
}
|
|
70
|
+
async function createPriceSets(manager, data) {
|
|
71
|
+
const priceSets = data.map((priceSetData) => {
|
|
72
|
+
return manager.create(PricingModels.PriceSet, priceSetData);
|
|
73
|
+
});
|
|
74
|
+
await manager.persistAndFlush(priceSets);
|
|
75
|
+
return priceSets;
|
|
76
|
+
}
|
|
77
|
+
async function createPriceSetMoneyAmounts(manager, data) {
|
|
78
|
+
const priceSetMoneyAmounts = data.map((priceSetMoneyAmountData) => {
|
|
79
|
+
return manager.create(PricingModels.PriceSetMoneyAmount, priceSetMoneyAmountData);
|
|
80
|
+
});
|
|
81
|
+
await manager.persistAndFlush(priceSetMoneyAmounts);
|
|
82
|
+
return priceSetMoneyAmounts;
|
|
83
|
+
}
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -3,10 +3,12 @@ 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.PricingModuleService = exports.MoneyAmountService = exports.CurrencyService = void 0;
|
|
6
|
+
exports.PricingModuleService = exports.PriceSetService = exports.MoneyAmountService = exports.CurrencyService = void 0;
|
|
7
7
|
var currency_1 = require("./currency");
|
|
8
8
|
Object.defineProperty(exports, "CurrencyService", { enumerable: true, get: function () { return __importDefault(currency_1).default; } });
|
|
9
9
|
var money_amount_1 = require("./money-amount");
|
|
10
10
|
Object.defineProperty(exports, "MoneyAmountService", { enumerable: true, get: function () { return __importDefault(money_amount_1).default; } });
|
|
11
|
+
var price_set_1 = require("./price-set");
|
|
12
|
+
Object.defineProperty(exports, "PriceSetService", { enumerable: true, get: function () { return __importDefault(price_set_1).default; } });
|
|
11
13
|
var pricing_module_1 = require("./pricing-module");
|
|
12
14
|
Object.defineProperty(exports, "PricingModuleService", { enumerable: true, get: function () { return __importDefault(pricing_module_1).default; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types";
|
|
2
|
+
import { PriceSet } from "../models";
|
|
3
|
+
type InjectedDependencies = {
|
|
4
|
+
priceSetRepository: DAL.RepositoryService;
|
|
5
|
+
};
|
|
6
|
+
export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
|
7
|
+
protected readonly priceSetRepository_: DAL.RepositoryService;
|
|
8
|
+
constructor({ priceSetRepository }: InjectedDependencies);
|
|
9
|
+
retrieve(priceSetId: string, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<TEntity>;
|
|
10
|
+
list(filters?: PricingTypes.FilterablePriceSetProps, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<TEntity[]>;
|
|
11
|
+
listAndCount(filters?: PricingTypes.FilterablePriceSetProps, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<[TEntity[], number]>;
|
|
12
|
+
private buildQueryForList;
|
|
13
|
+
create(data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context): Promise<TEntity[]>;
|
|
14
|
+
update(data: PricingTypes.UpdatePriceSetDTO[], sharedContext?: Context): Promise<TEntity[]>;
|
|
15
|
+
delete(ids: string[], sharedContext?: Context): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const types_1 = require("@medusajs/types");
|
|
16
|
+
const utils_1 = require("@medusajs/utils");
|
|
17
|
+
const _models_1 = require("../models");
|
|
18
|
+
class PriceSetService {
|
|
19
|
+
constructor({ priceSetRepository }) {
|
|
20
|
+
this.priceSetRepository_ = priceSetRepository;
|
|
21
|
+
}
|
|
22
|
+
async retrieve(priceSetId, config = {}, sharedContext = {}) {
|
|
23
|
+
return (await (0, utils_1.retrieveEntity)({
|
|
24
|
+
id: priceSetId,
|
|
25
|
+
entityName: _models_1.PriceSet.name,
|
|
26
|
+
repository: this.priceSetRepository_,
|
|
27
|
+
config,
|
|
28
|
+
sharedContext,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
async list(filters = {}, config = {}, sharedContext = {}) {
|
|
32
|
+
return (await this.priceSetRepository_.find(this.buildQueryForList(filters, config), sharedContext));
|
|
33
|
+
}
|
|
34
|
+
async listAndCount(filters = {}, config = {}, sharedContext = {}) {
|
|
35
|
+
return (await this.priceSetRepository_.findAndCount(this.buildQueryForList(filters, config), sharedContext));
|
|
36
|
+
}
|
|
37
|
+
buildQueryForList(filters = {}, config = {}) {
|
|
38
|
+
const queryOptions = utils_1.ModulesSdkUtils.buildQuery(filters, config);
|
|
39
|
+
if (filters.id) {
|
|
40
|
+
queryOptions.where.id = { $in: filters.id };
|
|
41
|
+
}
|
|
42
|
+
return queryOptions;
|
|
43
|
+
}
|
|
44
|
+
async create(data, sharedContext = {}) {
|
|
45
|
+
return (await this.priceSetRepository_.create(data, sharedContext));
|
|
46
|
+
}
|
|
47
|
+
async update(data, sharedContext = {}) {
|
|
48
|
+
return (await this.priceSetRepository_.update(data, sharedContext));
|
|
49
|
+
}
|
|
50
|
+
async delete(ids, sharedContext = {}) {
|
|
51
|
+
await this.priceSetRepository_.delete(ids, sharedContext);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = PriceSetService;
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, utils_1.InjectManager)("priceSetRepository_"),
|
|
57
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
58
|
+
__metadata("design:type", Function),
|
|
59
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
|
60
|
+
__metadata("design:returntype", Promise)
|
|
61
|
+
], PriceSetService.prototype, "retrieve", null);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, utils_1.InjectManager)("priceSetRepository_"),
|
|
64
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
65
|
+
__metadata("design:type", Function),
|
|
66
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
67
|
+
__metadata("design:returntype", Promise)
|
|
68
|
+
], PriceSetService.prototype, "list", null);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, utils_1.InjectManager)("priceSetRepository_"),
|
|
71
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
75
|
+
], PriceSetService.prototype, "listAndCount", null);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, utils_1.InjectTransactionManager)(utils_1.shouldForceTransaction, "priceSetRepository_"),
|
|
78
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
81
|
+
__metadata("design:returntype", Promise)
|
|
82
|
+
], PriceSetService.prototype, "create", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, utils_1.InjectTransactionManager)(utils_1.shouldForceTransaction, "priceSetRepository_"),
|
|
85
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
86
|
+
__metadata("design:type", Function),
|
|
87
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
88
|
+
__metadata("design:returntype", Promise)
|
|
89
|
+
], PriceSetService.prototype, "update", null);
|
|
90
|
+
__decorate([
|
|
91
|
+
(0, utils_1.InjectTransactionManager)(utils_1.doNotForceTransaction, "priceSetRepository_"),
|
|
92
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
93
|
+
__metadata("design:type", Function),
|
|
94
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
95
|
+
__metadata("design:returntype", Promise)
|
|
96
|
+
], PriceSetService.prototype, "delete", null);
|
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import { Context, DAL, FindConfig, InternalModuleDeclaration, ModuleJoinerConfig, PricingTypes } from "@medusajs/types";
|
|
2
|
-
import { Currency, MoneyAmount } from "../models";
|
|
3
|
-
import { CurrencyService, MoneyAmountService } from ".";
|
|
2
|
+
import { Currency, MoneyAmount, PriceSet } from "../models";
|
|
3
|
+
import { CurrencyService, MoneyAmountService, PriceSetService } from ".";
|
|
4
4
|
type InjectedDependencies = {
|
|
5
5
|
baseRepository: DAL.RepositoryService;
|
|
6
6
|
currencyService: CurrencyService<any>;
|
|
7
7
|
moneyAmountService: MoneyAmountService<any>;
|
|
8
|
+
priceSetService: PriceSetService<any>;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
type PricingContext = {
|
|
11
|
+
currency_code?: string;
|
|
12
|
+
};
|
|
13
|
+
export default class PricingModuleService<TPriceSet extends PriceSet = PriceSet, TMoneyAmount extends MoneyAmount = MoneyAmount, TCurrency extends Currency = Currency> implements PricingTypes.IPricingModuleService {
|
|
10
14
|
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
|
11
15
|
protected baseRepository_: DAL.RepositoryService;
|
|
12
16
|
protected readonly currencyService_: CurrencyService<TCurrency>;
|
|
13
17
|
protected readonly moneyAmountService_: MoneyAmountService<TMoneyAmount>;
|
|
14
|
-
|
|
18
|
+
protected readonly priceSetService_: PriceSetService<TPriceSet>;
|
|
19
|
+
constructor({ baseRepository, moneyAmountService, currencyService, priceSetService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
|
15
20
|
__joinerConfig(): ModuleJoinerConfig;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
calculatePrices(priceSetIds: string[], pricingContext: PricingContext, sharedContext?: Context): Promise<PricingTypes.CalculatedPriceSetDTO>;
|
|
22
|
+
retrieve(id: string, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<PricingTypes.PriceSetDTO>;
|
|
23
|
+
list(filters?: PricingTypes.FilterablePriceSetProps, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<PricingTypes.PriceSetDTO[]>;
|
|
24
|
+
listAndCount(filters?: PricingTypes.FilterablePriceSetProps, config?: FindConfig<PricingTypes.PriceSetDTO>, sharedContext?: Context): Promise<[PricingTypes.PriceSetDTO[], number]>;
|
|
25
|
+
create(data: PricingTypes.CreatePriceSetDTO[], sharedContext?: Context): Promise<PricingTypes.PriceSetDTO[]>;
|
|
26
|
+
update(data: PricingTypes.UpdatePriceSetDTO[], sharedContext?: Context): Promise<PricingTypes.PriceSetDTO[]>;
|
|
21
27
|
delete(ids: string[], sharedContext?: Context): Promise<void>;
|
|
28
|
+
retrieveMoneyAmount(id: string, config?: FindConfig<PricingTypes.MoneyAmountDTO>, sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO>;
|
|
29
|
+
listMoneyAmounts(filters?: PricingTypes.FilterableMoneyAmountProps, config?: FindConfig<PricingTypes.MoneyAmountDTO>, sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO[]>;
|
|
30
|
+
listAndCountMoneyAmounts(filters?: PricingTypes.FilterableMoneyAmountProps, config?: FindConfig<PricingTypes.MoneyAmountDTO>, sharedContext?: Context): Promise<[PricingTypes.MoneyAmountDTO[], number]>;
|
|
31
|
+
createMoneyAmounts(data: PricingTypes.CreateMoneyAmountDTO[], sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO[]>;
|
|
32
|
+
updateMoneyAmounts(data: PricingTypes.UpdateMoneyAmountDTO[], sharedContext?: Context): Promise<PricingTypes.MoneyAmountDTO[]>;
|
|
33
|
+
deleteMoneyAmounts(ids: string[], sharedContext?: Context): Promise<void>;
|
|
22
34
|
retrieveCurrency(code: string, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<PricingTypes.CurrencyDTO>;
|
|
23
35
|
listCurrencies(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<PricingTypes.CurrencyDTO[]>;
|
|
24
36
|
listAndCountCurrencies(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<[PricingTypes.CurrencyDTO[], number]>;
|
|
@@ -17,28 +17,99 @@ const utils_1 = require("@medusajs/utils");
|
|
|
17
17
|
const utils_2 = require("@medusajs/utils");
|
|
18
18
|
const joiner_config_1 = require("../joiner-config");
|
|
19
19
|
class PricingModuleService {
|
|
20
|
-
constructor({ baseRepository, moneyAmountService, currencyService, }, moduleDeclaration) {
|
|
20
|
+
constructor({ baseRepository, moneyAmountService, currencyService, priceSetService, }, moduleDeclaration) {
|
|
21
21
|
this.moduleDeclaration = moduleDeclaration;
|
|
22
22
|
this.baseRepository_ = baseRepository;
|
|
23
23
|
this.currencyService_ = currencyService;
|
|
24
24
|
this.moneyAmountService_ = moneyAmountService;
|
|
25
|
+
this.priceSetService_ = priceSetService;
|
|
25
26
|
}
|
|
26
27
|
__joinerConfig() {
|
|
27
28
|
return joiner_config_1.joinerConfig;
|
|
28
29
|
}
|
|
30
|
+
async calculatePrices(priceSetIds, pricingContext, sharedContext = {}) {
|
|
31
|
+
// Keeping this whole logic raw in here for now as they will undergo
|
|
32
|
+
// some changes, will abstract them out once we have a final version
|
|
33
|
+
const priceSetFilters = {
|
|
34
|
+
id: priceSetIds,
|
|
35
|
+
};
|
|
36
|
+
const priceSets = await this.list(priceSetFilters, {
|
|
37
|
+
select: [
|
|
38
|
+
"id",
|
|
39
|
+
"money_amounts.id",
|
|
40
|
+
"money_amounts.currency_code",
|
|
41
|
+
"money_amounts.amount",
|
|
42
|
+
"money_amounts.min_quantity",
|
|
43
|
+
"money_amounts.max_quantity",
|
|
44
|
+
],
|
|
45
|
+
relations: ["money_amounts"],
|
|
46
|
+
}, sharedContext);
|
|
47
|
+
const calculatedPrices = priceSets.map((priceSet) => {
|
|
48
|
+
// TODO: This will change with the rules engine selection,
|
|
49
|
+
// making a DB query directly instead
|
|
50
|
+
// This should look for a default price when no rules apply
|
|
51
|
+
// When no price is set, return null values for all cases
|
|
52
|
+
const selectedMoneyAmount = priceSet.money_amounts?.find((ma) => pricingContext.currency_code &&
|
|
53
|
+
ma.currency_code === pricingContext.currency_code);
|
|
54
|
+
return {
|
|
55
|
+
id: priceSet.id,
|
|
56
|
+
amount: selectedMoneyAmount?.amount || null,
|
|
57
|
+
currency_code: selectedMoneyAmount?.currency_code || null,
|
|
58
|
+
min_quantity: selectedMoneyAmount?.min_quantity || null,
|
|
59
|
+
max_quantity: selectedMoneyAmount?.max_quantity || null,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
return JSON.parse(JSON.stringify(calculatedPrices));
|
|
63
|
+
}
|
|
29
64
|
async retrieve(id, config = {}, sharedContext = {}) {
|
|
65
|
+
const priceSet = await this.priceSetService_.retrieve(id, config, sharedContext);
|
|
66
|
+
return this.baseRepository_.serialize(priceSet, {
|
|
67
|
+
populate: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async list(filters = {}, config = {}, sharedContext = {}) {
|
|
71
|
+
const priceSets = await this.priceSetService_.list(filters, config, sharedContext);
|
|
72
|
+
return this.baseRepository_.serialize(priceSets, {
|
|
73
|
+
populate: true,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async listAndCount(filters = {}, config = {}, sharedContext = {}) {
|
|
77
|
+
const [priceSets, count] = await this.priceSetService_.listAndCount(filters, config, sharedContext);
|
|
78
|
+
return [
|
|
79
|
+
await this.baseRepository_.serialize(priceSets, {
|
|
80
|
+
populate: true,
|
|
81
|
+
}),
|
|
82
|
+
count,
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
async create(data, sharedContext = {}) {
|
|
86
|
+
const priceSets = await this.priceSetService_.create(data, sharedContext);
|
|
87
|
+
return this.baseRepository_.serialize(priceSets, {
|
|
88
|
+
populate: true,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async update(data, sharedContext = {}) {
|
|
92
|
+
const priceSets = await this.priceSetService_.update(data, sharedContext);
|
|
93
|
+
return this.baseRepository_.serialize(priceSets, {
|
|
94
|
+
populate: true,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async delete(ids, sharedContext = {}) {
|
|
98
|
+
await this.priceSetService_.delete(ids, sharedContext);
|
|
99
|
+
}
|
|
100
|
+
async retrieveMoneyAmount(id, config = {}, sharedContext = {}) {
|
|
30
101
|
const moneyAmount = await this.moneyAmountService_.retrieve(id, config, sharedContext);
|
|
31
102
|
return this.baseRepository_.serialize(moneyAmount, {
|
|
32
103
|
populate: true,
|
|
33
104
|
});
|
|
34
105
|
}
|
|
35
|
-
async
|
|
106
|
+
async listMoneyAmounts(filters = {}, config = {}, sharedContext = {}) {
|
|
36
107
|
const moneyAmounts = await this.moneyAmountService_.list(filters, config, sharedContext);
|
|
37
108
|
return this.baseRepository_.serialize(moneyAmounts, {
|
|
38
109
|
populate: true,
|
|
39
110
|
});
|
|
40
111
|
}
|
|
41
|
-
async
|
|
112
|
+
async listAndCountMoneyAmounts(filters = {}, config = {}, sharedContext = {}) {
|
|
42
113
|
const [moneyAmounts, count] = await this.moneyAmountService_.listAndCount(filters, config, sharedContext);
|
|
43
114
|
return [
|
|
44
115
|
await this.baseRepository_.serialize(moneyAmounts, {
|
|
@@ -47,19 +118,19 @@ class PricingModuleService {
|
|
|
47
118
|
count,
|
|
48
119
|
];
|
|
49
120
|
}
|
|
50
|
-
async
|
|
121
|
+
async createMoneyAmounts(data, sharedContext = {}) {
|
|
51
122
|
const moneyAmounts = await this.moneyAmountService_.create(data, sharedContext);
|
|
52
123
|
return this.baseRepository_.serialize(moneyAmounts, {
|
|
53
124
|
populate: true,
|
|
54
125
|
});
|
|
55
126
|
}
|
|
56
|
-
async
|
|
127
|
+
async updateMoneyAmounts(data, sharedContext = {}) {
|
|
57
128
|
const moneyAmounts = await this.moneyAmountService_.update(data, sharedContext);
|
|
58
129
|
return this.baseRepository_.serialize(moneyAmounts, {
|
|
59
130
|
populate: true,
|
|
60
131
|
});
|
|
61
132
|
}
|
|
62
|
-
async
|
|
133
|
+
async deleteMoneyAmounts(ids, sharedContext = {}) {
|
|
63
134
|
await this.moneyAmountService_.delete(ids, sharedContext);
|
|
64
135
|
}
|
|
65
136
|
async retrieveCurrency(code, config = {}, sharedContext = {}) {
|
|
@@ -100,6 +171,13 @@ class PricingModuleService {
|
|
|
100
171
|
}
|
|
101
172
|
}
|
|
102
173
|
exports.default = PricingModuleService;
|
|
174
|
+
__decorate([
|
|
175
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
176
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
177
|
+
__metadata("design:type", Function),
|
|
178
|
+
__metadata("design:paramtypes", [Array, Object, Object]),
|
|
179
|
+
__metadata("design:returntype", Promise)
|
|
180
|
+
], PricingModuleService.prototype, "calculatePrices", null);
|
|
103
181
|
__decorate([
|
|
104
182
|
(0, utils_1.InjectManager)("baseRepository_"),
|
|
105
183
|
__param(2, (0, utils_1.MedusaContext)()),
|
|
@@ -142,6 +220,48 @@ __decorate([
|
|
|
142
220
|
__metadata("design:paramtypes", [Array, Object]),
|
|
143
221
|
__metadata("design:returntype", Promise)
|
|
144
222
|
], PricingModuleService.prototype, "delete", null);
|
|
223
|
+
__decorate([
|
|
224
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
225
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
226
|
+
__metadata("design:type", Function),
|
|
227
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
|
228
|
+
__metadata("design:returntype", Promise)
|
|
229
|
+
], PricingModuleService.prototype, "retrieveMoneyAmount", null);
|
|
230
|
+
__decorate([
|
|
231
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
232
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
233
|
+
__metadata("design:type", Function),
|
|
234
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
235
|
+
__metadata("design:returntype", Promise)
|
|
236
|
+
], PricingModuleService.prototype, "listMoneyAmounts", null);
|
|
237
|
+
__decorate([
|
|
238
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
|
239
|
+
__param(2, (0, utils_1.MedusaContext)()),
|
|
240
|
+
__metadata("design:type", Function),
|
|
241
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
242
|
+
__metadata("design:returntype", Promise)
|
|
243
|
+
], PricingModuleService.prototype, "listAndCountMoneyAmounts", null);
|
|
244
|
+
__decorate([
|
|
245
|
+
(0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
|
|
246
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
247
|
+
__metadata("design:type", Function),
|
|
248
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
249
|
+
__metadata("design:returntype", Promise)
|
|
250
|
+
], PricingModuleService.prototype, "createMoneyAmounts", null);
|
|
251
|
+
__decorate([
|
|
252
|
+
(0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
|
|
253
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
254
|
+
__metadata("design:type", Function),
|
|
255
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
256
|
+
__metadata("design:returntype", Promise)
|
|
257
|
+
], PricingModuleService.prototype, "updateMoneyAmounts", null);
|
|
258
|
+
__decorate([
|
|
259
|
+
(0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
|
|
260
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
261
|
+
__metadata("design:type", Function),
|
|
262
|
+
__metadata("design:paramtypes", [Array, Object]),
|
|
263
|
+
__metadata("design:returntype", Promise)
|
|
264
|
+
], PricingModuleService.prototype, "deleteMoneyAmounts", null);
|
|
145
265
|
__decorate([
|
|
146
266
|
(0, utils_1.InjectManager)("baseRepository_"),
|
|
147
267
|
__param(2, (0, utils_1.MedusaContext)()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/pricing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next-20230912130318",
|
|
4
4
|
"description": "Medusa Pricing module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"typescript": "^5.1.6"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@medusajs/modules-sdk": "
|
|
51
|
-
"@medusajs/types": "
|
|
52
|
-
"@medusajs/utils": "
|
|
50
|
+
"@medusajs/modules-sdk": "1.11.0-next-20230912130318",
|
|
51
|
+
"@medusajs/types": "1.11.1-next-20230912130318",
|
|
52
|
+
"@medusajs/utils": "1.10.1-next-20230912130318",
|
|
53
53
|
"@mikro-orm/core": "5.7.12",
|
|
54
54
|
"@mikro-orm/migrations": "5.7.12",
|
|
55
55
|
"@mikro-orm/postgresql": "5.7.12",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Migration20230830085850 = void 0;
|
|
4
|
-
const migrations_1 = require("@mikro-orm/migrations");
|
|
5
|
-
class Migration20230830085850 extends migrations_1.Migration {
|
|
6
|
-
async up() {
|
|
7
|
-
this.addSql('create table "currency" ("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null, constraint "currency_pkey" primary key ("code"));');
|
|
8
|
-
this.addSql('create table "money_amount" ("id" text not null, "currency_code" text null, "amount" numeric null, "min_quantity" numeric null, "max_quantity" numeric null, constraint "money_amount_pkey" primary key ("id"));');
|
|
9
|
-
this.addSql('create index "IDX_money_amount_currency_code" on "money_amount" ("currency_code");');
|
|
10
|
-
this.addSql('alter table "money_amount" add constraint "money_amount_currency_code_foreign" foreign key ("currency_code") references "currency" ("code") on update cascade on delete set null;');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.Migration20230830085850 = Migration20230830085850;
|