@medusajs/promotion 0.0.5-snapshot-20240503181318 → 0.0.5-snapshot-20240516152256
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -18
- package/dist/models/campaign.d.ts.map +1 -1
- package/dist/models/campaign.js +1 -3
- package/dist/models/promotion.d.ts +1 -0
- package/dist/models/promotion.d.ts.map +1 -1
- package/dist/models/promotion.js +8 -3
- package/dist/module-definition.d.ts +0 -2
- package/dist/module-definition.d.ts.map +1 -1
- package/dist/module-definition.js +1 -43
- package/dist/repositories/index.d.ts +0 -1
- package/dist/repositories/index.d.ts.map +1 -1
- package/dist/repositories/index.js +1 -3
- package/dist/services/promotion-module.d.ts +8 -0
- package/dist/services/promotion-module.d.ts.map +1 -1
- package/dist/services/promotion-module.js +78 -9
- package/dist/types/campaign-budget.d.ts +3 -3
- package/dist/types/campaign-budget.d.ts.map +1 -1
- package/dist/types/campaign.d.ts +2 -2
- package/dist/types/campaign.d.ts.map +1 -1
- package/dist/types/promotion.d.ts +2 -2
- package/dist/types/promotion.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/initialize/index.d.ts +0 -5
- package/dist/initialize/index.d.ts.map +0 -1
- package/dist/initialize/index.js +0 -16
- package/dist/loaders/connection.d.ts +0 -5
- package/dist/loaders/connection.d.ts.map +0 -1
- package/dist/loaders/connection.js +0 -41
- package/dist/loaders/container.d.ts +0 -3
- package/dist/loaders/container.d.ts.map +0 -1
- package/dist/loaders/container.js +0 -34
- package/dist/loaders/index.d.ts +0 -3
- package/dist/loaders/index.d.ts.map +0 -1
- package/dist/loaders/index.js +0 -18
- package/dist/repositories/campaign.d.ts +0 -16
- package/dist/repositories/campaign.d.ts.map +0 -1
- package/dist/repositories/campaign.js +0 -90
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import { moduleDefinition
|
1
|
+
import { moduleDefinition } from "./module-definition";
|
2
2
|
export default moduleDefinition;
|
3
|
-
export { revertMigration, runMigrations };
|
4
|
-
export * from "./initialize";
|
5
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,eAAe,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,22 +1,4 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.runMigrations = exports.revertMigration = void 0;
|
18
3
|
const module_definition_1 = require("./module-definition");
|
19
|
-
Object.defineProperty(exports, "revertMigration", { enumerable: true, get: function () { return module_definition_1.revertMigration; } });
|
20
|
-
Object.defineProperty(exports, "runMigrations", { enumerable: true, get: function () { return module_definition_1.runMigrations; } });
|
21
4
|
exports.default = module_definition_1.moduleDefinition;
|
22
|
-
__exportStar(require("./initialize"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/models/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAErC,OAAO,EAEL,UAAU,EAMV,aAAa,EAId,MAAM,iBAAiB,CAAA;AACxB,OAAO,cAAc,MAAM,mBAAmB,CAAA;AAC9C,OAAO,SAAS,MAAM,aAAa,CAAA;AAEnC,KAAK,iBAAiB,GAAG,QAAQ,CAAA;AACjC,KAAK,cAAc,GACf,aAAa,GACb,UAAU,GACV,WAAW,GACX,SAAS,GACT,GAAG,CAAC,8BAA8B,CAAA;AAItC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,CAAC,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,iBAAiB,CAAA;IAGpD,EAAE,EAAG,MAAM,CAAA;IAIX,IAAI,EAAE,MAAM,CAAA;IAIZ,WAAW,EAAE,MAAM,GAAG,IAAI,CAAO;IAGjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IAO9B,mBAAmB,EAAE,MAAM,CAAA;IAM3B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAO;IAM7B,OAAO,EAAE,IAAI,GAAG,IAAI,CAAO;IAQ3B,MAAM,EAAE,cAAc,GAAG,IAAI,CAAO;
|
1
|
+
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/models/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAErC,OAAO,EAEL,UAAU,EAMV,aAAa,EAId,MAAM,iBAAiB,CAAA;AACxB,OAAO,cAAc,MAAM,mBAAmB,CAAA;AAC9C,OAAO,SAAS,MAAM,aAAa,CAAA;AAEnC,KAAK,iBAAiB,GAAG,QAAQ,CAAA;AACjC,KAAK,cAAc,GACf,aAAa,GACb,UAAU,GACV,WAAW,GACX,SAAS,GACT,GAAG,CAAC,8BAA8B,CAAA;AAItC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,CAAC,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,iBAAiB,CAAA;IAGpD,EAAE,EAAG,MAAM,CAAA;IAIX,IAAI,EAAE,MAAM,CAAA;IAIZ,WAAW,EAAE,MAAM,GAAG,IAAI,CAAO;IAGjC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IAO9B,mBAAmB,EAAE,MAAM,CAAA;IAM3B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAO;IAM7B,OAAO,EAAE,IAAI,GAAG,IAAI,CAAO;IAQ3B,MAAM,EAAE,cAAc,GAAG,IAAI,CAAO;IAGpC,UAAU,gCAAkC;IAO5C,UAAU,EAAE,IAAI,CAAA;IAQhB,UAAU,EAAE,IAAI,CAAA;IAGhB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAO;IAG9B,QAAQ;IAKR,MAAM;CAGP"}
|
package/dist/models/campaign.js
CHANGED
@@ -83,9 +83,7 @@ __decorate([
|
|
83
83
|
__metadata("design:type", Object)
|
84
84
|
], Campaign.prototype, "budget", void 0);
|
85
85
|
__decorate([
|
86
|
-
(0, core_1.OneToMany)(() => promotion_1.default, (promotion) => promotion.campaign,
|
87
|
-
orphanRemoval: true,
|
88
|
-
}),
|
86
|
+
(0, core_1.OneToMany)(() => promotion_1.default, (promotion) => promotion.campaign),
|
89
87
|
__metadata("design:type", Object)
|
90
88
|
], Campaign.prototype, "promotions", void 0);
|
91
89
|
__decorate([
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/models/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAO1D,OAAO,EAEL,UAAU,EASV,aAAa,EAId,MAAM,iBAAiB,CAAA;AACxB,OAAO,iBAAiB,MAAM,sBAAsB,CAAA;AACpD,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OA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,QAAQ;IAKR,MAAM;CAGP"}
|
package/dist/models/promotion.js
CHANGED
@@ -19,7 +19,7 @@ const campaign_1 = __importDefault(require("./campaign"));
|
|
19
19
|
const promotion_rule_1 = __importDefault(require("./promotion-rule"));
|
20
20
|
let Promotion = class Promotion {
|
21
21
|
constructor() {
|
22
|
-
this.
|
22
|
+
this.campaign_id = null;
|
23
23
|
this.is_automatic = false;
|
24
24
|
this.rules = new core_1.Collection(this);
|
25
25
|
this.deleted_at = null;
|
@@ -46,13 +46,18 @@ __decorate([
|
|
46
46
|
__metadata("design:type", String)
|
47
47
|
], Promotion.prototype, "code", void 0);
|
48
48
|
__decorate([
|
49
|
-
(0, utils_1.Searchable)(),
|
50
49
|
(0, core_1.ManyToOne)(() => campaign_1.default, {
|
50
|
+
columnType: "text",
|
51
51
|
fieldName: "campaign_id",
|
52
52
|
nullable: true,
|
53
|
-
|
53
|
+
mapToPk: true,
|
54
|
+
onDelete: "set null",
|
54
55
|
}),
|
55
56
|
__metadata("design:type", Object)
|
57
|
+
], Promotion.prototype, "campaign_id", void 0);
|
58
|
+
__decorate([
|
59
|
+
(0, core_1.ManyToOne)(() => campaign_1.default, { persist: false }),
|
60
|
+
__metadata("design:type", Object)
|
56
61
|
], Promotion.prototype, "campaign", void 0);
|
57
62
|
__decorate([
|
58
63
|
(0, core_1.Property)({ columnType: "boolean", default: false }),
|
@@ -1,5 +1,3 @@
|
|
1
1
|
import { ModuleExports } from "@medusajs/types";
|
2
|
-
export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
|
3
|
-
export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
|
4
2
|
export declare const moduleDefinition: ModuleExports;
|
5
3
|
//# sourceMappingURL=module-definition.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"module-definition.d.ts","sourceRoot":"","sources":["../src/module-definition.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"module-definition.d.ts","sourceRoot":"","sources":["../src/module-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAK/C,eAAO,MAAM,gBAAgB,EAAE,aAE9B,CAAA"}
|
@@ -1,50 +1,8 @@
|
|
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
|
-
};
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
-
};
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.moduleDefinition =
|
30
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
31
|
-
const utils_1 = require("@medusajs/utils");
|
32
|
-
const Models = __importStar(require("./models"));
|
3
|
+
exports.moduleDefinition = void 0;
|
33
4
|
const _services_1 = require("./services");
|
34
|
-
const connection_1 = __importDefault(require("./loaders/connection"));
|
35
|
-
const container_1 = __importDefault(require("./loaders/container"));
|
36
|
-
const migrationScriptOptions = {
|
37
|
-
moduleName: modules_sdk_1.Modules.PROMOTION,
|
38
|
-
models: Models,
|
39
|
-
pathToMigrations: __dirname + "/migrations",
|
40
|
-
};
|
41
|
-
exports.runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
|
42
|
-
exports.revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
|
43
5
|
const service = _services_1.PromotionModuleService;
|
44
|
-
const loaders = [container_1.default, connection_1.default];
|
45
6
|
exports.moduleDefinition = {
|
46
7
|
service,
|
47
|
-
loaders,
|
48
|
-
runMigrations: exports.runMigrations,
|
49
|
-
revertMigration: exports.revertMigration,
|
50
8
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA"}
|
@@ -1,7 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
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
|
-
var campaign_1 = require("./campaign");
|
7
|
-
Object.defineProperty(exports, "CampaignRepository", { enumerable: true, get: function () { return campaign_1.CampaignRepository; } });
|
@@ -64,6 +64,14 @@ export default class PromotionModuleService<TApplicationMethod extends Applicati
|
|
64
64
|
updateCampaigns(data: PromotionTypes.UpdateCampaignDTO, sharedContext?: Context): Promise<PromotionTypes.CampaignDTO>;
|
65
65
|
updateCampaigns(data: PromotionTypes.UpdateCampaignDTO[], sharedContext?: Context): Promise<PromotionTypes.CampaignDTO[]>;
|
66
66
|
protected updateCampaigns_(data: PromotionTypes.UpdateCampaignDTO[], sharedContext?: Context): Promise<TCampaign[]>;
|
67
|
+
addPromotionsToCampaign(data: PromotionTypes.AddPromotionsToCampaignDTO, sharedContext?: Context): Promise<{
|
68
|
+
ids: string[];
|
69
|
+
}>;
|
70
|
+
protected addPromotionsToCampaign_(data: PromotionTypes.AddPromotionsToCampaignDTO, sharedContext?: Context): Promise<string[]>;
|
71
|
+
removePromotionsFromCampaign(data: PromotionTypes.AddPromotionsToCampaignDTO, sharedContext?: Context): Promise<{
|
72
|
+
ids: string[];
|
73
|
+
}>;
|
74
|
+
protected removePromotionsFromCampaign_(data: PromotionTypes.AddPromotionsToCampaignDTO, sharedContext?: Context): Promise<string[]>;
|
67
75
|
}
|
68
76
|
export {};
|
69
77
|
//# sourceMappingURL=promotion-module.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion-module.d.ts","sourceRoot":"","sources":["../../src/services/promotion-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EASL,eAAe,EAMhB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACd,SAAS,EACT,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,0BAA0B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Aa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC;IAEhC,eAAe,CACnB,IAAI,EAAE,cAAc,CAAC,iBAAiB,EAAE,EACxC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC;cAuBxB,gBAAgB,CAC9B,IAAI,EAAE,cAAc,CAAC,iBAAiB,EAAE,EACvB,aAAa,GAAE,OAAY;IAoDxC,eAAe,CACnB,IAAI,EAAE,cAAc,CAAC,iBAAiB,EACtC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC;IAEhC,eAAe,CACnB,IAAI,EAAE,cAAc,CAAC,iBAAiB,EAAE,EACxC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC;cAuBxB,gBAAgB,CAC9B,IAAI,EAAE,cAAc,CAAC,iBAAiB,EAAE,EACvB,aAAa,GAAE,OAAY;IAgDxC,uBAAuB,CAC3B,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC/C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;cAWb,wBAAwB,CACtC,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC9B,aAAa,GAAE,OAAY;IAqCxC,4BAA4B,CAChC,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC/C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;cAOb,6BAA6B,CAC3C,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC9B,aAAa,GAAE,OAAY;CAiC/C"}
|
@@ -254,10 +254,11 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
254
254
|
}
|
255
255
|
promotionsData.push({
|
256
256
|
...promotionData,
|
257
|
-
|
257
|
+
campaign_id: campaignId,
|
258
258
|
});
|
259
259
|
}
|
260
260
|
const createdPromotions = await this.promotionService_.create(promotionsData, sharedContext);
|
261
|
+
const promotionsToAdd = [];
|
261
262
|
for (const promotion of createdPromotions) {
|
262
263
|
const applMethodData = promotionCodeApplicationMethodDataMap.get(promotion.code);
|
263
264
|
const campaignData = promotionCodeCampaignMap.get(promotion.code);
|
@@ -297,8 +298,14 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
297
298
|
await this.createPromotionRulesAndValues_(promotionCodeRulesDataMap.get(promotion.code) || [], "promotions", promotion, sharedContext);
|
298
299
|
}
|
299
300
|
const createdApplicationMethods = await this.applicationMethodService_.create(applicationMethodsData, sharedContext);
|
300
|
-
|
301
|
-
|
301
|
+
const createdCampaigns = await this.createCampaigns(campaignsData, sharedContext);
|
302
|
+
for (const campaignData of campaignsData) {
|
303
|
+
const promotions = campaignData.promotions;
|
304
|
+
const campaign = createdCampaigns.find((c) => c.campaign_identifier === campaignData.campaign_identifier);
|
305
|
+
if (!campaign || !promotions || !promotions.length) {
|
306
|
+
continue;
|
307
|
+
}
|
308
|
+
await this.addPromotionsToCampaign({ id: campaign.id, promotion_ids: promotions.map((p) => p.id) }, sharedContext);
|
302
309
|
}
|
303
310
|
for (const applicationMethod of createdApplicationMethods) {
|
304
311
|
await this.createPromotionRulesAndValues_(methodTargetRulesMap.get(applicationMethod.promotion.id) || [], "method_target_rules", applicationMethod, sharedContext);
|
@@ -331,7 +338,7 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
331
338
|
const applicationMethodsData = [];
|
332
339
|
for (const { application_method: applicationMethodData, campaign_id: campaignId, ...promotionData } of data) {
|
333
340
|
if (campaignId) {
|
334
|
-
promotionsData.push({ ...promotionData,
|
341
|
+
promotionsData.push({ ...promotionData, campaign_id: campaignId });
|
335
342
|
}
|
336
343
|
else {
|
337
344
|
promotionsData.push(promotionData);
|
@@ -491,16 +498,12 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
491
498
|
const campaignBudgetsData = [];
|
492
499
|
const campaignIdentifierBudgetMap = new Map();
|
493
500
|
for (const createCampaignData of data) {
|
494
|
-
const { budget: campaignBudgetData,
|
495
|
-
const promotionsToAdd = promotions
|
496
|
-
? await this.list({ id: promotions.map((p) => p.id) }, { take: null }, sharedContext)
|
497
|
-
: [];
|
501
|
+
const { budget: campaignBudgetData, ...campaignData } = createCampaignData;
|
498
502
|
if (campaignBudgetData) {
|
499
503
|
campaignIdentifierBudgetMap.set(campaignData.campaign_identifier, campaignBudgetData);
|
500
504
|
}
|
501
505
|
campaignsData.push({
|
502
506
|
...campaignData,
|
503
|
-
promotions: promotionsToAdd,
|
504
507
|
});
|
505
508
|
}
|
506
509
|
const createdCampaigns = await this.campaignService_.create(campaignsData, sharedContext);
|
@@ -551,6 +554,46 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
551
554
|
}
|
552
555
|
return updatedCampaigns;
|
553
556
|
}
|
557
|
+
async addPromotionsToCampaign(data, sharedContext) {
|
558
|
+
const ids = await this.addPromotionsToCampaign_(data, sharedContext);
|
559
|
+
return { ids };
|
560
|
+
}
|
561
|
+
// TODO:
|
562
|
+
// - introduce currency_code to promotion
|
563
|
+
// - allow promotions to be queried by currency code
|
564
|
+
// - when the above is present, validate adding promotion to campaign based on currency code
|
565
|
+
async addPromotionsToCampaign_(data, sharedContext = {}) {
|
566
|
+
const { id, promotion_ids: promotionIds = [] } = data;
|
567
|
+
const campaign = await this.campaignService_.retrieve(id, {}, sharedContext);
|
568
|
+
const promotionsToAdd = await this.promotionService_.list({ id: promotionIds, campaign_id: null }, { take: null }, sharedContext);
|
569
|
+
const diff = (0, utils_1.arrayDifference)(promotionsToAdd.map((p) => p.id), promotionIds);
|
570
|
+
if (diff.length > 0) {
|
571
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Cannot add promotions (${diff.join(",")}) to campaign. These promotions are either already part of a campaign or not found.`);
|
572
|
+
}
|
573
|
+
await this.promotionService_.update(promotionsToAdd.map((promotion) => ({
|
574
|
+
id: promotion.id,
|
575
|
+
campaign_id: campaign.id,
|
576
|
+
})), sharedContext);
|
577
|
+
return promotionsToAdd.map((promo) => promo.id);
|
578
|
+
}
|
579
|
+
async removePromotionsFromCampaign(data, sharedContext) {
|
580
|
+
const ids = await this.removePromotionsFromCampaign_(data, sharedContext);
|
581
|
+
return { ids };
|
582
|
+
}
|
583
|
+
async removePromotionsFromCampaign_(data, sharedContext = {}) {
|
584
|
+
const { id, promotion_ids: promotionIds = [] } = data;
|
585
|
+
await this.campaignService_.retrieve(id, {}, sharedContext);
|
586
|
+
const promotionsToRemove = await this.promotionService_.list({ id: promotionIds }, { take: null }, sharedContext);
|
587
|
+
const diff = (0, utils_1.arrayDifference)(promotionsToRemove.map((p) => p.id), promotionIds);
|
588
|
+
if (diff.length > 0) {
|
589
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Promotions with ids (${diff.join(",")}) not found.`);
|
590
|
+
}
|
591
|
+
await this.promotionService_.update(promotionsToRemove.map((promotion) => ({
|
592
|
+
id: promotion.id,
|
593
|
+
campaign_id: null,
|
594
|
+
})), sharedContext);
|
595
|
+
return promotionsToRemove.map((promo) => promo.id);
|
596
|
+
}
|
554
597
|
}
|
555
598
|
exports.default = PromotionModuleService;
|
556
599
|
__decorate([
|
@@ -700,3 +743,29 @@ __decorate([
|
|
700
743
|
__metadata("design:paramtypes", [Array, Object]),
|
701
744
|
__metadata("design:returntype", Promise)
|
702
745
|
], PromotionModuleService.prototype, "updateCampaigns_", null);
|
746
|
+
__decorate([
|
747
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
748
|
+
__metadata("design:type", Function),
|
749
|
+
__metadata("design:paramtypes", [Object, Object]),
|
750
|
+
__metadata("design:returntype", Promise)
|
751
|
+
], PromotionModuleService.prototype, "addPromotionsToCampaign", null);
|
752
|
+
__decorate([
|
753
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
754
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
755
|
+
__metadata("design:type", Function),
|
756
|
+
__metadata("design:paramtypes", [Object, Object]),
|
757
|
+
__metadata("design:returntype", Promise)
|
758
|
+
], PromotionModuleService.prototype, "addPromotionsToCampaign_", null);
|
759
|
+
__decorate([
|
760
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
761
|
+
__metadata("design:type", Function),
|
762
|
+
__metadata("design:paramtypes", [Object, Object]),
|
763
|
+
__metadata("design:returntype", Promise)
|
764
|
+
], PromotionModuleService.prototype, "removePromotionsFromCampaign", null);
|
765
|
+
__decorate([
|
766
|
+
(0, utils_1.InjectTransactionManager)("baseRepository_"),
|
767
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
768
|
+
__metadata("design:type", Function),
|
769
|
+
__metadata("design:paramtypes", [Object, Object]),
|
770
|
+
__metadata("design:returntype", Promise)
|
771
|
+
], PromotionModuleService.prototype, "removePromotionsFromCampaign_", null);
|
@@ -1,15 +1,15 @@
|
|
1
1
|
import { CampaignBudgetTypeValues } from "@medusajs/types";
|
2
2
|
import { Campaign } from "../models";
|
3
3
|
export interface CreateCampaignBudgetDTO {
|
4
|
-
type
|
5
|
-
limit
|
4
|
+
type?: CampaignBudgetTypeValues;
|
5
|
+
limit?: number;
|
6
6
|
used?: number;
|
7
7
|
campaign?: Campaign | string;
|
8
8
|
}
|
9
9
|
export interface UpdateCampaignBudgetDTO {
|
10
10
|
id: string;
|
11
11
|
type?: CampaignBudgetTypeValues;
|
12
|
-
limit?: number
|
12
|
+
limit?: number;
|
13
13
|
used?: number;
|
14
14
|
}
|
15
15
|
//# sourceMappingURL=campaign-budget.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"campaign-budget.d.ts","sourceRoot":"","sources":["../../src/types/campaign-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,wBAAwB,CAAA;
|
1
|
+
{"version":3,"file":"campaign-budget.d.ts","sourceRoot":"","sources":["../../src/types/campaign-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,wBAAwB,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,wBAAwB,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;CACd"}
|
package/dist/types/campaign.d.ts
CHANGED
@@ -5,8 +5,8 @@ export interface CreateCampaignDTO {
|
|
5
5
|
description?: string;
|
6
6
|
currency?: string;
|
7
7
|
campaign_identifier: string;
|
8
|
-
starts_at
|
9
|
-
ends_at
|
8
|
+
starts_at?: Date;
|
9
|
+
ends_at?: Date;
|
10
10
|
promotions?: (PromotionDTO | Promotion)[];
|
11
11
|
}
|
12
12
|
export interface UpdateCampaignDTO {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/types/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAAA;
|
1
|
+
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/types/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAC1C;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAC1C"}
|
@@ -3,13 +3,13 @@ export interface CreatePromotionDTO {
|
|
3
3
|
code: string;
|
4
4
|
type: PromotionTypeValues;
|
5
5
|
is_automatic?: boolean;
|
6
|
-
|
6
|
+
campaign_id?: string;
|
7
7
|
}
|
8
8
|
export interface UpdatePromotionDTO {
|
9
9
|
id: string;
|
10
10
|
code?: string;
|
11
11
|
type?: PromotionTypeValues;
|
12
12
|
is_automatic?: boolean;
|
13
|
-
|
13
|
+
campaign_id?: string;
|
14
14
|
}
|
15
15
|
//# sourceMappingURL=promotion.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/types/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,mBAAmB,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,
|
1
|
+
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/types/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,mBAAmB,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,mBAAmB,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/promotion",
|
3
|
-
"version": "0.0.5-snapshot-
|
3
|
+
"version": "0.0.5-snapshot-20240516152256",
|
4
4
|
"description": "Medusa Promotion module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"@mikro-orm/cli": "5.9.7",
|
41
41
|
"cross-env": "^5.2.1",
|
42
42
|
"jest": "^29.6.3",
|
43
|
-
"medusa-test-utils": "
|
43
|
+
"medusa-test-utils": "1.1.45-snapshot-20240516152256",
|
44
44
|
"rimraf": "^3.0.2",
|
45
45
|
"ts-jest": "^29.1.1",
|
46
46
|
"ts-node": "^10.9.1",
|
@@ -48,9 +48,9 @@
|
|
48
48
|
"typescript": "^5.1.6"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@medusajs/modules-sdk": "1.
|
52
|
-
"@medusajs/types": "1.
|
53
|
-
"@medusajs/utils": "1.
|
51
|
+
"@medusajs/modules-sdk": "1.13.0-snapshot-20240516152256",
|
52
|
+
"@medusajs/types": "1.12.0-snapshot-20240516152256",
|
53
|
+
"@medusajs/utils": "1.12.0-snapshot-20240516152256",
|
54
54
|
"@mikro-orm/core": "5.9.7",
|
55
55
|
"@mikro-orm/migrations": "5.9.7",
|
56
56
|
"@mikro-orm/postgresql": "5.9.7",
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/modules-sdk";
|
2
|
-
import { IPromotionModuleService, ModulesSdkTypes } from "@medusajs/types";
|
3
|
-
import { InitializeModuleInjectableDependencies } from "../types";
|
4
|
-
export declare const initialize: (options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration | InternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IPromotionModuleService>;
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EAI1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AAEjE,eAAO,MAAM,UAAU,aAEjB,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,GAC7D,yBAAyB,GACzB,yBAAyB,yBACN,sCAAsC,KAC5D,QAAQ,uBAAuB,CAYjC,CAAA"}
|
package/dist/initialize/index.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.initialize = void 0;
|
4
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
5
|
-
const module_definition_1 = require("../module-definition");
|
6
|
-
const initialize = async (options, injectedDependencies) => {
|
7
|
-
const loaded = await modules_sdk_1.MedusaModule.bootstrap({
|
8
|
-
moduleKey: modules_sdk_1.Modules.PROMOTION,
|
9
|
-
defaultPath: modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.PROMOTION],
|
10
|
-
declaration: options,
|
11
|
-
injectedDependencies,
|
12
|
-
moduleExports: module_definition_1.moduleDefinition,
|
13
|
-
});
|
14
|
-
return loaded[modules_sdk_1.Modules.PROMOTION];
|
15
|
-
};
|
16
|
-
exports.initialize = initialize;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
|
2
|
-
import { ModulesSdkTypes } from "@medusajs/types";
|
3
|
-
declare const _default: ({ options, container, logger, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
|
4
|
-
export default _default;
|
5
|
-
//# sourceMappingURL=connection.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/loaders/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,EAEd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;0DAU5C,cACC,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,CAChE,sBACmB,yBAAyB,KAC5C,QAAQ,IAAI,CAAC;AAVhB,wBAuBC"}
|
@@ -1,41 +0,0 @@
|
|
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
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
27
|
-
const utils_1 = require("@medusajs/utils");
|
28
|
-
const PromotionModels = __importStar(require("../models"));
|
29
|
-
exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
|
30
|
-
const entities = Object.values(PromotionModels);
|
31
|
-
const pathToMigrations = __dirname + "/../migrations";
|
32
|
-
await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
|
33
|
-
moduleName: modules_sdk_1.Modules.PROMOTION,
|
34
|
-
entities,
|
35
|
-
container,
|
36
|
-
options,
|
37
|
-
moduleDeclaration,
|
38
|
-
logger,
|
39
|
-
pathToMigrations,
|
40
|
-
});
|
41
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/loaders/container.ts"],"names":[],"mappings":";AAKA,wBAIE"}
|
@@ -1,34 +0,0 @@
|
|
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
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
const utils_1 = require("@medusajs/utils");
|
27
|
-
const ModuleModels = __importStar(require("../models"));
|
28
|
-
const ModuleRepositories = __importStar(require("../repositories"));
|
29
|
-
const ModuleServices = __importStar(require("../services"));
|
30
|
-
exports.default = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
|
31
|
-
moduleModels: ModuleModels,
|
32
|
-
moduleRepositories: ModuleRepositories,
|
33
|
-
moduleServices: ModuleServices,
|
34
|
-
});
|
package/dist/loaders/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
|
package/dist/loaders/index.js
DELETED
@@ -1,18 +0,0 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./connection"), exports);
|
18
|
-
__exportStar(require("./container"), exports);
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Context } from "@medusajs/types";
|
2
|
-
import { DALUtils } from "@medusajs/utils";
|
3
|
-
import { Campaign } from "../models";
|
4
|
-
import { CreateCampaignDTO, UpdateCampaignDTO } from "../types";
|
5
|
-
declare const CampaignRepository_base: new ({ manager }: {
|
6
|
-
manager: any;
|
7
|
-
}) => DALUtils.MikroOrmBaseRepository<Campaign>;
|
8
|
-
export declare class CampaignRepository extends CampaignRepository_base {
|
9
|
-
create(data: CreateCampaignDTO[], context?: Context): Promise<Campaign[]>;
|
10
|
-
update(data: {
|
11
|
-
entity: Campaign;
|
12
|
-
update: UpdateCampaignDTO;
|
13
|
-
}[], context?: Context): Promise<Campaign[]>;
|
14
|
-
}
|
15
|
-
export {};
|
16
|
-
//# sourceMappingURL=campaign.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/repositories/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;;;;AAE7D,qBAAa,kBAAmB,SAAQ,uBAEvC;IACO,MAAM,CACV,IAAI,EAAE,iBAAiB,EAAE,EACzB,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiDhB,MAAM,CACV,IAAI,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,EAAE,EACvD,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,QAAQ,EAAE,CAAC;CAoFvB"}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CampaignRepository = void 0;
|
4
|
-
const utils_1 = require("@medusajs/utils");
|
5
|
-
const _models_1 = require("../models");
|
6
|
-
class CampaignRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFactory(_models_1.Campaign) {
|
7
|
-
async create(data, context = {}) {
|
8
|
-
const manager = this.getActiveManager(context);
|
9
|
-
const promotionIdsToUpsert = [];
|
10
|
-
const campaignIdentifierPromotionsMap = new Map();
|
11
|
-
data.forEach((campaignData) => {
|
12
|
-
const campaignPromotionIds = campaignData.promotions?.map((p) => p.id) || [];
|
13
|
-
promotionIdsToUpsert.push(...campaignPromotionIds);
|
14
|
-
campaignIdentifierPromotionsMap.set(campaignData.campaign_identifier, campaignPromotionIds);
|
15
|
-
delete campaignData.promotions;
|
16
|
-
});
|
17
|
-
const existingPromotions = await manager.find(_models_1.Promotion, {
|
18
|
-
id: promotionIdsToUpsert,
|
19
|
-
});
|
20
|
-
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.id, promotion]));
|
21
|
-
const createdCampaigns = await super.create(data, context);
|
22
|
-
for (const createdCampaign of createdCampaigns) {
|
23
|
-
const campaignPromotionIds = campaignIdentifierPromotionsMap.get(createdCampaign.campaign_identifier) || [];
|
24
|
-
for (const campaignPromotionId of campaignPromotionIds) {
|
25
|
-
const promotion = existingPromotionsMap.get(campaignPromotionId);
|
26
|
-
if (!promotion) {
|
27
|
-
continue;
|
28
|
-
}
|
29
|
-
createdCampaign.promotions.add(promotion);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return createdCampaigns;
|
33
|
-
}
|
34
|
-
async update(data, context = {}) {
|
35
|
-
const manager = this.getActiveManager(context);
|
36
|
-
const promotionIdsToUpsert = [];
|
37
|
-
const campaignIds = [];
|
38
|
-
const campaignPromotionIdsMap = new Map();
|
39
|
-
data.forEach(({ update: campaignData }) => {
|
40
|
-
const campaignPromotionIds = campaignData.promotions?.map((p) => p.id);
|
41
|
-
campaignIds.push(campaignData.id);
|
42
|
-
if (campaignPromotionIds) {
|
43
|
-
promotionIdsToUpsert.push(...campaignPromotionIds);
|
44
|
-
campaignPromotionIdsMap.set(campaignData.id, campaignPromotionIds);
|
45
|
-
}
|
46
|
-
delete campaignData.promotions;
|
47
|
-
});
|
48
|
-
const existingCampaigns = await manager.find(_models_1.Campaign, { id: campaignIds }, { populate: ["promotions"] });
|
49
|
-
const promotionIds = existingCampaigns
|
50
|
-
.map((campaign) => campaign.promotions?.map((p) => p.id))
|
51
|
-
.flat(1)
|
52
|
-
.concat(promotionIdsToUpsert);
|
53
|
-
const existingPromotions = await manager.find(_models_1.Promotion, {
|
54
|
-
id: promotionIds,
|
55
|
-
});
|
56
|
-
const existingCampaignsMap = new Map(existingCampaigns.map((campaign) => [campaign.id, campaign]));
|
57
|
-
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.id, promotion]));
|
58
|
-
const updatedCampaigns = await super.update(data, context);
|
59
|
-
for (const updatedCampaign of updatedCampaigns) {
|
60
|
-
const upsertPromotionIds = campaignPromotionIdsMap.get(updatedCampaign.id);
|
61
|
-
if (!upsertPromotionIds) {
|
62
|
-
continue;
|
63
|
-
}
|
64
|
-
const existingPromotionIds = (existingCampaignsMap.get(updatedCampaign.id)?.promotions || []).map((p) => p.id);
|
65
|
-
for (const existingPromotionId of existingPromotionIds) {
|
66
|
-
const promotion = existingPromotionsMap.get(existingPromotionId);
|
67
|
-
if (!promotion) {
|
68
|
-
continue;
|
69
|
-
}
|
70
|
-
if (!upsertPromotionIds.includes(existingPromotionId)) {
|
71
|
-
updatedCampaign.promotions.remove(promotion);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
for (const promotionIdToAdd of upsertPromotionIds) {
|
75
|
-
const promotion = existingPromotionsMap.get(promotionIdToAdd);
|
76
|
-
if (!promotion) {
|
77
|
-
continue;
|
78
|
-
}
|
79
|
-
if (existingPromotionIds.includes(promotionIdToAdd)) {
|
80
|
-
continue;
|
81
|
-
}
|
82
|
-
else {
|
83
|
-
updatedCampaign.promotions.add(promotion);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
return updatedCampaigns;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
exports.CampaignRepository = CampaignRepository;
|