@sgftech/medusa-plugin-marketplace-v2 0.2.0 → 0.2.2

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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * attaches the product to the store
4
+ */
5
+ import { MedusaRequest, MedusaResponse } from "@medusajs/medusa";
6
+ export declare const POST: (req: MedusaRequest, res: MedusaResponse) => Promise<void>;
7
+ /**
8
+ *
9
+ * attaches the product to the store
10
+ */
11
+ export declare const DELETE: (req: MedusaRequest, res: MedusaResponse) => Promise<void>;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ /**
3
+ *
4
+ * attaches the product to the store
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __generator = (this && this.__generator) || function (thisArg, body) {
16
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
17
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
+ function verb(n) { return function (v) { return step([n, v]); }; }
19
+ function step(op) {
20
+ if (f) throw new TypeError("Generator is already executing.");
21
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
+ if (y = 0, t) op = [op[0] & 2, t.value];
24
+ switch (op[0]) {
25
+ case 0: case 1: t = op; break;
26
+ case 4: _.label++; return { value: op[1], done: false };
27
+ case 5: _.label++; y = op[1]; op = [0]; continue;
28
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
+ default:
30
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
+ if (t[2]) _.ops.pop();
35
+ _.trys.pop(); continue;
36
+ }
37
+ op = body.call(thisArg, _);
38
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
+ }
41
+ };
42
+ var __importDefault = (this && this.__importDefault) || function (mod) {
43
+ return (mod && mod.__esModule) ? mod : { "default": mod };
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.DELETE = exports.POST = void 0;
47
+ var lodash_1 = __importDefault(require("lodash"));
48
+ var POST = function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
49
+ var productId, storeService, productService, logger, activeStore, user, product, e_1, e_2;
50
+ var _a;
51
+ return __generator(this, function (_b) {
52
+ switch (_b.label) {
53
+ case 0:
54
+ if (!req.user.userId) {
55
+ res.sendStatus(401);
56
+ return [2 /*return*/];
57
+ }
58
+ lodash_1.default.isString(req.params.id);
59
+ productId = req.params.id;
60
+ storeService = req.scope.resolve("storeService");
61
+ productService = req.scope.resolve("productService");
62
+ logger = req.scope.resolve("logger");
63
+ activeStore = req.scope.resolve("activeStore");
64
+ _b.label = 1;
65
+ case 1:
66
+ _b.trys.push([1, 8, , 9]);
67
+ if (!!(activeStore === null || activeStore === void 0 ? void 0 : activeStore.members)) return [3 /*break*/, 3];
68
+ if (!activeStore) return [3 /*break*/, 3];
69
+ return [4 /*yield*/, storeService.retrieveRelationsByStoreId(activeStore.id, {
70
+ relations: ["members"]
71
+ })];
72
+ case 2:
73
+ activeStore = _b.sent();
74
+ _b.label = 3;
75
+ case 3:
76
+ if (activeStore.members) {
77
+ user = (_a = activeStore.members) === null || _a === void 0 ? void 0 : _a.find(function (member) { return member.id === req.user.userId; });
78
+ if ((user === null || user === void 0 ? void 0 : user.is_admin) != true) {
79
+ res.status(401).send({
80
+ error: "Unauthorized you are not an admin of this store"
81
+ });
82
+ return [2 /*return*/];
83
+ }
84
+ }
85
+ _b.label = 4;
86
+ case 4:
87
+ _b.trys.push([4, 6, , 7]);
88
+ return [4 /*yield*/, productService.associateProductWithStore({ id: productId }, activeStore.id)];
89
+ case 5:
90
+ product = _b.sent();
91
+ res.status(200).send(product);
92
+ return [3 /*break*/, 7];
93
+ case 6:
94
+ e_1 = _b.sent();
95
+ logger.error("unable to attach product ".concat(e_1));
96
+ res.sendStatus(500);
97
+ return [2 /*return*/];
98
+ case 7: return [3 /*break*/, 9];
99
+ case 8:
100
+ e_2 = _b.sent();
101
+ logger.error("unable to attach product ".concat(e_2));
102
+ res.sendStatus(500);
103
+ return [2 /*return*/];
104
+ case 9: return [2 /*return*/];
105
+ }
106
+ });
107
+ }); };
108
+ exports.POST = POST;
109
+ /**
110
+ *
111
+ * attaches the product to the store
112
+ */
113
+ var DELETE = function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
114
+ var productId, storeService, productService, logger, activeStore, user, product, e_3, e_4;
115
+ var _a;
116
+ return __generator(this, function (_b) {
117
+ switch (_b.label) {
118
+ case 0:
119
+ if (!req.user.userId) {
120
+ res.sendStatus(401);
121
+ return [2 /*return*/];
122
+ }
123
+ lodash_1.default.isString(req.params.id);
124
+ productId = req.params.id;
125
+ storeService = req.scope.resolve("storeService");
126
+ productService = req.scope.resolve("productService");
127
+ logger = req.scope.resolve("logger");
128
+ activeStore = req.scope.resolve("activeStore");
129
+ _b.label = 1;
130
+ case 1:
131
+ _b.trys.push([1, 8, , 9]);
132
+ if (!!(activeStore === null || activeStore === void 0 ? void 0 : activeStore.members)) return [3 /*break*/, 3];
133
+ if (!activeStore) return [3 /*break*/, 3];
134
+ return [4 /*yield*/, storeService.retrieveRelationsByStoreId(activeStore.id, {
135
+ relations: ["members"]
136
+ })];
137
+ case 2:
138
+ activeStore = _b.sent();
139
+ _b.label = 3;
140
+ case 3:
141
+ if (activeStore.members) {
142
+ user = (_a = activeStore.members) === null || _a === void 0 ? void 0 : _a.find(function (member) { return member.id === req.user.userId; });
143
+ if ((user === null || user === void 0 ? void 0 : user.is_admin) != true) {
144
+ res.status(401).send({
145
+ error: "Unauthorized you are not an admin of this store"
146
+ });
147
+ return [2 /*return*/];
148
+ }
149
+ }
150
+ _b.label = 4;
151
+ case 4:
152
+ _b.trys.push([4, 6, , 7]);
153
+ return [4 /*yield*/, productService.dissociateProductFromStore({ id: productId }, activeStore.id)];
154
+ case 5:
155
+ product = _b.sent();
156
+ res.status(200).send(product);
157
+ return [3 /*break*/, 7];
158
+ case 6:
159
+ e_3 = _b.sent();
160
+ logger.error("unable to attach product ".concat(e_3));
161
+ res.sendStatus(500);
162
+ return [2 /*return*/];
163
+ case 7: return [3 /*break*/, 9];
164
+ case 8:
165
+ e_4 = _b.sent();
166
+ logger.error("unable to attach product ".concat(e_4));
167
+ res.sendStatus(500);
168
+ return [2 /*return*/];
169
+ case 9: return [2 /*return*/];
170
+ }
171
+ });
172
+ }); };
173
+ exports.DELETE = DELETE;
174
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../src/api/admin/attach-product/[id]/route.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMH,kDAAuB;AAIhB,IAAM,IAAI,GAAG,UAChB,GAAkB,EAClB,GAAmB;;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523 implements MigrationInterface {
3
+ name: string;
4
+ up(queryRunner: QueryRunner): Promise<void>;
5
+ down(queryRunner: QueryRunner): Promise<void>;
6
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.UserMigration1666588571523 = void 0;
40
+ //
41
+ //
42
+ var UserMigration1666588571523 = /** @class */ (function () {
43
+ function UserMigration1666588571523() {
44
+ this.name = "UserMigration1666588571523";
45
+ }
46
+ UserMigration1666588571523.prototype.up = function (queryRunner) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var query;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ query = "ALTER TABLE public.\"user\" ADD COLUMN IF NOT EXISTS \"inviter\" text\n ";
53
+ return [4 /*yield*/, queryRunner.query(query)];
54
+ case 1:
55
+ _a.sent();
56
+ return [2 /*return*/];
57
+ }
58
+ });
59
+ });
60
+ };
61
+ UserMigration1666588571523.prototype.down = function (queryRunner) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var query;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ query = "ALTER TABLE public.\"user\" DROP COLUMN \"inviter\";\n ;";
68
+ return [4 /*yield*/, queryRunner.query(query)];
69
+ case 1:
70
+ _a.sent();
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ });
75
+ };
76
+ return UserMigration1666588571523;
77
+ }());
78
+ exports.UserMigration1666588571523 = UserMigration1666588571523;
79
+ //# sourceMappingURL=1666588571523-user.inviter.migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"1666588571523-user.inviter.migration.js","sourceRoot":"","sources":["../../src/migrations/1666588571523-user.inviter.migration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,EAAE;AAEF,EAAE;AACF;IAAA;QACI,SAAI,GAAG,4BAA4B,CAAC;IAexC,CAAC;IAbgB,uCAAE,GAAf,UAAgB,WAAwB;;;;;;wBAC9B,KAAK,GAAG,iFACb,CAAC;wBAEF,qBAAM,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;wBAA9B,SAA8B,CAAC;;;;;KAClC;IAEY,yCAAI,GAAjB,UAAkB,WAAwB;;;;;;wBAChC,KAAK,GAAG,iEACZ,CAAC;wBAEH,qBAAM,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,EAAA;;wBAA9B,SAA8B,CAAC;;;;;KAClC;IACL,iCAAC;AAAD,CAAC,AAhBD,IAgBC;AAhBY,gEAA0B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgftech/medusa-plugin-marketplace-v2",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A plugin to initiate marketplace",
5
5
  "author": "Govind Diwakar",
6
6
  "license": "MIT",