@medusajs/promotion 0.0.1
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/README.md +3 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/initialize/index.d.ts +5 -0
- package/dist/initialize/index.d.ts.map +1 -0
- package/dist/initialize/index.js +16 -0
- package/dist/joiner-config.d.ts +8 -0
- package/dist/joiner-config.d.ts.map +1 -0
- package/dist/joiner-config.js +28 -0
- package/dist/loaders/connection.d.ts +5 -0
- package/dist/loaders/connection.d.ts.map +1 -0
- package/dist/loaders/connection.js +41 -0
- package/dist/loaders/container.d.ts +5 -0
- package/dist/loaders/container.d.ts.map +1 -0
- package/dist/loaders/container.js +53 -0
- package/dist/loaders/index.d.ts +3 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +18 -0
- package/dist/migrations/Migration20231221104256.d.ts +5 -0
- package/dist/migrations/Migration20231221104256.d.ts.map +1 -0
- package/dist/migrations/Migration20231221104256.js +19 -0
- package/dist/models/application-method.d.ts +21 -0
- package/dist/models/application-method.d.ts.map +1 -0
- package/dist/models/application-method.js +98 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +10 -0
- package/dist/models/promotion.d.ts +20 -0
- package/dist/models/promotion.d.ts.map +1 -0
- package/dist/models/promotion.js +94 -0
- package/dist/module-definition.d.ts +3 -0
- package/dist/module-definition.d.ts.map +1 -0
- package/dist/module-definition.js +15 -0
- package/dist/repositories/application-method.d.ts +17 -0
- package/dist/repositories/application-method.d.ts.map +1 -0
- package/dist/repositories/application-method.js +59 -0
- package/dist/repositories/index.d.ts +4 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +9 -0
- package/dist/repositories/promotion.d.ts +17 -0
- package/dist/repositories/promotion.d.ts.map +1 -0
- package/dist/repositories/promotion.js +69 -0
- package/dist/scripts/bin/run-migration-down.d.ts +4 -0
- package/dist/scripts/bin/run-migration-down.d.ts.map +1 -0
- package/dist/scripts/bin/run-migration-down.js +32 -0
- package/dist/scripts/bin/run-migration-up.d.ts +4 -0
- package/dist/scripts/bin/run-migration-up.d.ts.map +1 -0
- package/dist/scripts/bin/run-migration-up.js +32 -0
- package/dist/scripts/bin/run-seed.d.ts +4 -0
- package/dist/scripts/bin/run-seed.d.ts.map +1 -0
- package/dist/scripts/bin/run-seed.js +38 -0
- package/dist/scripts/index.d.ts +3 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +18 -0
- package/dist/scripts/migration-down.d.ts +10 -0
- package/dist/scripts/migration-down.d.ts.map +1 -0
- package/dist/scripts/migration-down.js +53 -0
- package/dist/scripts/migration-up.d.ts +10 -0
- package/dist/scripts/migration-up.d.ts.map +1 -0
- package/dist/scripts/migration-up.js +57 -0
- package/dist/scripts/seed.d.ts +5 -0
- package/dist/scripts/seed.d.ts.map +1 -0
- package/dist/scripts/seed.js +54 -0
- package/dist/services/application-method.d.ts +18 -0
- package/dist/services/application-method.d.ts.map +1 -0
- package/dist/services/application-method.js +91 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +12 -0
- package/dist/services/promotion-module.d.ts +21 -0
- package/dist/services/promotion-module.d.ts.map +1 -0
- package/dist/services/promotion-module.js +88 -0
- package/dist/services/promotion.d.ts +18 -0
- package/dist/services/promotion.d.ts.map +1 -0
- package/dist/services/promotion.js +91 -0
- package/dist/types/application-method.d.ts +13 -0
- package/dist/types/application-method.d.ts.map +1 -0
- package/dist/types/application-method.js +2 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/promotion.d.ts +10 -0
- package/dist/types/promotion.d.ts.map +1 -0
- package/dist/types/promotion.js +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/validations/application-method.d.ts +3 -0
- package/dist/utils/validations/application-method.d.ts.map +1 -0
- package/dist/utils/validations/application-method.js +26 -0
- package/dist/utils/validations/index.d.ts +2 -0
- package/dist/utils/validations/index.d.ts.map +1 -0
- package/dist/utils/validations/index.js +17 -0
- package/package.json +63 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationMethodRepository = void 0;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
const _models_1 = require("../models");
|
|
6
|
+
class ApplicationMethodRepository extends utils_1.DALUtils.MikroOrmBaseRepository {
|
|
7
|
+
constructor({ manager }) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
// eslint-disable-next-line prefer-rest-params
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.manager_ = manager;
|
|
12
|
+
}
|
|
13
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
14
|
+
const manager = this.getActiveManager(context);
|
|
15
|
+
const findOptions_ = { ...findOptions };
|
|
16
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
17
|
+
return await manager.find(_models_1.ApplicationMethod, findOptions_.where, findOptions_.options);
|
|
18
|
+
}
|
|
19
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
20
|
+
const manager = this.getActiveManager(context);
|
|
21
|
+
const findOptions_ = { ...findOptions };
|
|
22
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
23
|
+
return await manager.findAndCount(_models_1.ApplicationMethod, findOptions_.where, findOptions_.options);
|
|
24
|
+
}
|
|
25
|
+
async delete(ids, context = {}) {
|
|
26
|
+
const manager = this.getActiveManager(context);
|
|
27
|
+
await manager.nativeDelete(_models_1.ApplicationMethod, { id: { $in: ids } }, {});
|
|
28
|
+
}
|
|
29
|
+
async create(data, context = {}) {
|
|
30
|
+
const manager = this.getActiveManager(context);
|
|
31
|
+
const applicationMethods = data.map((applicationMethodData) => {
|
|
32
|
+
return manager.create(_models_1.ApplicationMethod, applicationMethodData);
|
|
33
|
+
});
|
|
34
|
+
manager.persist(applicationMethods);
|
|
35
|
+
return applicationMethods;
|
|
36
|
+
}
|
|
37
|
+
async update(data, context = {}) {
|
|
38
|
+
const manager = this.getActiveManager(context);
|
|
39
|
+
const applicationMethodIds = data.map((applicationMethodData) => applicationMethodData.id);
|
|
40
|
+
const existingApplicationMethods = await this.find({
|
|
41
|
+
where: {
|
|
42
|
+
id: {
|
|
43
|
+
$in: applicationMethodIds,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}, context);
|
|
47
|
+
const existingApplicationMethodMap = new Map(existingApplicationMethods.map((applicationMethod) => [applicationMethod.id, applicationMethod]));
|
|
48
|
+
const applicationMethods = data.map((applicationMethodData) => {
|
|
49
|
+
const existingApplicationMethod = existingApplicationMethodMap.get(applicationMethodData.id);
|
|
50
|
+
if (!existingApplicationMethod) {
|
|
51
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `ApplicationMethod with id "${applicationMethodData.id}" not found`);
|
|
52
|
+
}
|
|
53
|
+
return manager.assign(existingApplicationMethod, applicationMethodData);
|
|
54
|
+
});
|
|
55
|
+
manager.persist(applicationMethods);
|
|
56
|
+
return applicationMethods;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.ApplicationMethodRepository = ApplicationMethodRepository;
|
|
@@ -0,0 +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;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromotionRepository = exports.ApplicationMethodRepository = exports.BaseRepository = void 0;
|
|
4
|
+
var utils_1 = require("@medusajs/utils");
|
|
5
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
|
|
6
|
+
var application_method_1 = require("./application-method");
|
|
7
|
+
Object.defineProperty(exports, "ApplicationMethodRepository", { enumerable: true, get: function () { return application_method_1.ApplicationMethodRepository; } });
|
|
8
|
+
var promotion_1 = require("./promotion");
|
|
9
|
+
Object.defineProperty(exports, "PromotionRepository", { enumerable: true, get: function () { return promotion_1.PromotionRepository; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, DAL } from "@medusajs/types";
|
|
2
|
+
import { DALUtils } from "@medusajs/utils";
|
|
3
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
4
|
+
import { Promotion } from "../models";
|
|
5
|
+
import { CreatePromotionDTO, UpdatePromotionDTO } from "../types";
|
|
6
|
+
export declare class PromotionRepository extends DALUtils.MikroOrmBaseRepository {
|
|
7
|
+
protected readonly manager_: SqlEntityManager;
|
|
8
|
+
constructor({ manager }: {
|
|
9
|
+
manager: SqlEntityManager;
|
|
10
|
+
});
|
|
11
|
+
find(findOptions?: DAL.FindOptions<Promotion>, context?: Context): Promise<Promotion[]>;
|
|
12
|
+
findAndCount(findOptions?: DAL.FindOptions<Promotion>, context?: Context): Promise<[Promotion[], number]>;
|
|
13
|
+
delete(ids: string[], context?: Context): Promise<void>;
|
|
14
|
+
create(data: CreatePromotionDTO[], context?: Context): Promise<Promotion[]>;
|
|
15
|
+
update(data: UpdatePromotionDTO[], context?: Context): Promise<Promotion[]>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=promotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/repositories/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAe,MAAM,iBAAiB,CAAA;AAMvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAEjE,qBAAa,mBAAoB,SAAQ,QAAQ,CAAC,sBAAsB;IACtE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAA;gBAEjC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,gBAAgB,CAAA;KAAE;IAOhD,IAAI,CACR,WAAW,GAAE,GAAG,CAAC,WAAW,CAAC,SAAS,CAAiB,EACvD,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC;IAiBjB,YAAY,CAChB,WAAW,GAAE,GAAG,CAAC,WAAW,CAAC,SAAS,CAAiB,EACvD,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;IAiB3B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,OAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,MAAM,CACV,IAAI,EAAE,kBAAkB,EAAE,EAC1B,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC;IAYjB,MAAM,CACV,IAAI,EAAE,kBAAkB,EAAE,EAC1B,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,SAAS,EAAE,CAAC;CAsCxB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromotionRepository = 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 PromotionRepository 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.Promotion, 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.Promotion, findOptions_.where, findOptions_.options);
|
|
31
|
+
}
|
|
32
|
+
async delete(ids, context = {}) {
|
|
33
|
+
const manager = this.getActiveManager(context);
|
|
34
|
+
await manager.nativeDelete(_models_1.Promotion, { id: { $in: ids } }, {});
|
|
35
|
+
}
|
|
36
|
+
async create(data, context = {}) {
|
|
37
|
+
const manager = this.getActiveManager(context);
|
|
38
|
+
const promotions = data.map((promotionData) => {
|
|
39
|
+
return manager.create(_models_1.Promotion, promotionData);
|
|
40
|
+
});
|
|
41
|
+
manager.persist(promotions);
|
|
42
|
+
return promotions;
|
|
43
|
+
}
|
|
44
|
+
async update(data, context = {}) {
|
|
45
|
+
const manager = this.getActiveManager(context);
|
|
46
|
+
const promotionIds = data.map((promotionData) => promotionData.id);
|
|
47
|
+
const existingPromotions = await this.find({
|
|
48
|
+
where: {
|
|
49
|
+
id: {
|
|
50
|
+
$in: promotionIds,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}, context);
|
|
54
|
+
const existingPromotionMap = new Map(existingPromotions.map((promotion) => [
|
|
55
|
+
promotion.id,
|
|
56
|
+
promotion,
|
|
57
|
+
]));
|
|
58
|
+
const promotions = data.map((promotionData) => {
|
|
59
|
+
const existingPromotion = existingPromotionMap.get(promotionData.id);
|
|
60
|
+
if (!existingPromotion) {
|
|
61
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Promotion with id "${promotionData.id}" not found`);
|
|
62
|
+
}
|
|
63
|
+
return manager.assign(existingPromotion, promotionData);
|
|
64
|
+
});
|
|
65
|
+
manager.persist(promotions);
|
|
66
|
+
return promotions;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.PromotionRepository = PromotionRepository;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migration-down.d.ts","sourceRoot":"","sources":["../../../src/scripts/bin/run-migration-down.ts"],"names":[],"mappings":";;AAEA,wBAKI"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.default = (async () => {
|
|
28
|
+
const { revertMigration } = await Promise.resolve().then(() => __importStar(require("../migration-down")));
|
|
29
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
30
|
+
config();
|
|
31
|
+
await revertMigration();
|
|
32
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migration-up.d.ts","sourceRoot":"","sources":["../../../src/scripts/bin/run-migration-up.ts"],"names":[],"mappings":";;AAEA,wBAKI"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.default = (async () => {
|
|
28
|
+
const { runMigrations } = await Promise.resolve().then(() => __importStar(require("../migration-up")));
|
|
29
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
30
|
+
config();
|
|
31
|
+
await runMigrations();
|
|
32
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-seed.d.ts","sourceRoot":"","sources":["../../../src/scripts/bin/run-seed.ts"],"names":[],"mappings":";;AAQA,wBAUI"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
const os_1 = require("os");
|
|
28
|
+
const seed_1 = require("../seed");
|
|
29
|
+
const args = process.argv;
|
|
30
|
+
const path = args.pop();
|
|
31
|
+
exports.default = (async () => {
|
|
32
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
33
|
+
config();
|
|
34
|
+
if (!path) {
|
|
35
|
+
throw new Error(`filePath is required.${os_1.EOL}Example: medusa-promotion-seed <filePath>`);
|
|
36
|
+
}
|
|
37
|
+
await (0, seed_1.run)({ path });
|
|
38
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./migration-up"), exports);
|
|
18
|
+
__exportStar(require("./migration-down"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
|
|
2
|
+
/**
|
|
3
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
4
|
+
* he is in charge of reverting the migrations.
|
|
5
|
+
* @param options
|
|
6
|
+
* @param logger
|
|
7
|
+
* @param moduleDeclaration
|
|
8
|
+
*/
|
|
9
|
+
export declare function revertMigration({ options, logger, }?: Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=migration-down.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-down.d.ts","sourceRoot":"","sources":["../../src/scripts/migration-down.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKxE;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,EACpC,OAAO,EACP,MAAM,GACP,GAAE,IAAI,CACL,aAAa,CAAC,eAAe,CAAC,8BAA8B,CAAC,EAC7D,SAAS,GAAG,QAAQ,CAChB,iBAuBL"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
exports.revertMigration = void 0;
|
|
27
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
|
29
|
+
const PromotionModels = __importStar(require("../models"));
|
|
30
|
+
/**
|
|
31
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
32
|
+
* he is in charge of reverting the migrations.
|
|
33
|
+
* @param options
|
|
34
|
+
* @param logger
|
|
35
|
+
* @param moduleDeclaration
|
|
36
|
+
*/
|
|
37
|
+
async function revertMigration({ options, logger, } = {}) {
|
|
38
|
+
logger ?? (logger = console);
|
|
39
|
+
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig(modules_sdk_1.Modules.PROMOTION, options);
|
|
40
|
+
const entities = Object.values(PromotionModels);
|
|
41
|
+
const pathToMigrations = __dirname + "/../migrations";
|
|
42
|
+
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
|
43
|
+
try {
|
|
44
|
+
const migrator = orm.getMigrator();
|
|
45
|
+
await migrator.down();
|
|
46
|
+
logger?.info("Promotion module migration executed");
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
logger?.error(`Promotion module migration failed to run - Error: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
await orm.close();
|
|
52
|
+
}
|
|
53
|
+
exports.revertMigration = revertMigration;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
|
|
2
|
+
/**
|
|
3
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
4
|
+
* he is in charge of running the migrations.
|
|
5
|
+
* @param options
|
|
6
|
+
* @param logger
|
|
7
|
+
* @param moduleDeclaration
|
|
8
|
+
*/
|
|
9
|
+
export declare function runMigrations({ options, logger, }?: Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=migration-up.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-up.d.ts","sourceRoot":"","sources":["../../src/scripts/migration-up.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKxE;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAO,EACP,MAAM,GACP,GAAE,IAAI,CACL,aAAa,CAAC,eAAe,CAAC,8BAA8B,CAAC,EAC7D,SAAS,GAAG,QAAQ,CAChB,iBAmCL"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
exports.runMigrations = void 0;
|
|
27
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
|
29
|
+
const PromotionModels = __importStar(require("../models"));
|
|
30
|
+
/**
|
|
31
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
32
|
+
* he is in charge of running the migrations.
|
|
33
|
+
* @param options
|
|
34
|
+
* @param logger
|
|
35
|
+
* @param moduleDeclaration
|
|
36
|
+
*/
|
|
37
|
+
async function runMigrations({ options, logger, } = {}) {
|
|
38
|
+
logger ?? (logger = console);
|
|
39
|
+
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig(modules_sdk_1.Modules.PROMOTION, options);
|
|
40
|
+
const entities = Object.values(PromotionModels);
|
|
41
|
+
const pathToMigrations = __dirname + "/../migrations";
|
|
42
|
+
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
|
43
|
+
try {
|
|
44
|
+
const migrator = orm.getMigrator();
|
|
45
|
+
const pendingMigrations = await migrator.getPendingMigrations();
|
|
46
|
+
logger.info(`Running pending migrations: ${JSON.stringify(pendingMigrations, null, 2)}`);
|
|
47
|
+
await migrator.up({
|
|
48
|
+
migrations: pendingMigrations.map((m) => m.name),
|
|
49
|
+
});
|
|
50
|
+
logger.info("Promotion module migration executed");
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
logger.error(`Promotion module migration failed to run - Error: ${error}`);
|
|
54
|
+
}
|
|
55
|
+
await orm.close();
|
|
56
|
+
}
|
|
57
|
+
exports.runMigrations = runMigrations;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
|
|
2
|
+
export declare function run({ options, logger, path, }: Partial<Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">> & {
|
|
3
|
+
path: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/scripts/seed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAU,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAOxE,wBAAsB,GAAG,CAAC,EACxB,OAAO,EACP,MAAM,EACN,IAAI,GACL,EAAE,OAAO,CACR,IAAI,CACF,aAAa,CAAC,eAAe,CAAC,8BAA8B,CAAC,EAC7D,SAAS,GAAG,QAAQ,CACrB,CACF,GAAG;IACF,IAAI,EAAE,MAAM,CAAA;CACb,iBAsCA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
exports.run = void 0;
|
|
27
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
|
29
|
+
const PromotionModels = __importStar(require("../models"));
|
|
30
|
+
const os_1 = require("os");
|
|
31
|
+
const path_1 = require("path");
|
|
32
|
+
async function run({ options, logger, path, }) {
|
|
33
|
+
logger ?? (logger = console);
|
|
34
|
+
logger.info(`Loading seed data from ${path}...`);
|
|
35
|
+
const { promotionsData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
|
|
36
|
+
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: promotionsData.${os_1.EOL}${e}`);
|
|
37
|
+
throw e;
|
|
38
|
+
});
|
|
39
|
+
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig(modules_sdk_1.Modules.PROMOTION, options);
|
|
40
|
+
const entities = Object.values(PromotionModels);
|
|
41
|
+
const pathToMigrations = __dirname + "/../migrations";
|
|
42
|
+
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
|
43
|
+
const manager = orm.em.fork();
|
|
44
|
+
try {
|
|
45
|
+
logger.info("Inserting promotions..");
|
|
46
|
+
// TODO: implement promotions seed data
|
|
47
|
+
// await createPromotions(manager, promotionsData)
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
|
|
51
|
+
}
|
|
52
|
+
await orm.close(true);
|
|
53
|
+
}
|
|
54
|
+
exports.run = run;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Context, DAL, FindConfig, PromotionTypes } from "@medusajs/types";
|
|
2
|
+
import { ApplicationMethod } from "../models";
|
|
3
|
+
import { CreateApplicationMethodDTO, UpdateApplicationMethodDTO } from "../types";
|
|
4
|
+
type InjectedDependencies = {
|
|
5
|
+
applicationMethodRepository: DAL.RepositoryService;
|
|
6
|
+
};
|
|
7
|
+
export default class ApplicationMethodService<TEntity extends ApplicationMethod = ApplicationMethod> {
|
|
8
|
+
protected readonly applicationMethodRepository_: DAL.RepositoryService;
|
|
9
|
+
constructor({ applicationMethodRepository }: InjectedDependencies);
|
|
10
|
+
retrieve(applicationMethodId: string, config?: FindConfig<PromotionTypes.ApplicationMethodDTO>, sharedContext?: Context): Promise<TEntity>;
|
|
11
|
+
list(filters?: PromotionTypes.FilterableApplicationMethodProps, config?: FindConfig<PromotionTypes.ApplicationMethodDTO>, sharedContext?: Context): Promise<TEntity[]>;
|
|
12
|
+
listAndCount(filters?: PromotionTypes.FilterableApplicationMethodProps, config?: FindConfig<PromotionTypes.ApplicationMethodDTO>, sharedContext?: Context): Promise<[TEntity[], number]>;
|
|
13
|
+
create(data: CreateApplicationMethodDTO[], sharedContext?: Context): Promise<TEntity[]>;
|
|
14
|
+
update(data: UpdateApplicationMethodDTO[], sharedContext?: Context): Promise<TEntity[]>;
|
|
15
|
+
delete(ids: string[], sharedContext?: Context): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=application-method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../src/services/application-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAQ1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,UAAU,CAAA;AAEjB,KAAK,oBAAoB,GAAG;IAC1B,2BAA2B,EAAE,GAAG,CAAC,iBAAiB,CAAA;CACnD,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,wBAAwB,CAC3C,OAAO,SAAS,iBAAiB,GAAG,iBAAiB;IAErD,SAAS,CAAC,QAAQ,CAAC,4BAA4B,EAAE,GAAG,CAAC,iBAAiB,CAAA;gBAE1D,EAAE,2BAA2B,EAAE,EAAE,oBAAoB;IAK3D,QAAQ,CACZ,mBAAmB,EAAE,MAAM,EAC3B,MAAM,GAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAM,EAC3C,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,OAAO,CAAC;IAcb,IAAI,CACR,OAAO,GAAE,cAAc,CAAC,gCAAqC,EAC7D,MAAM,GAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAM,EAC3C,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,OAAO,EAAE,CAAC;IAaf,YAAY,CAChB,OAAO,GAAE,cAAc,CAAC,gCAAqC,EAC7D,MAAM,GAAE,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAM,EAC3C,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC;IAazB,MAAM,CACV,IAAI,EAAE,0BAA0B,EAAE,EACjB,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,OAAO,EAAE,CAAC;IAOf,MAAM,CACV,IAAI,EAAE,0BAA0B,EAAE,EACjB,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,OAAO,EAAE,CAAC;IAOf,MAAM,CACV,GAAG,EAAE,MAAM,EAAE,EACI,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,IAAI,CAAC;CAGjB"}
|