@medusajs/medusa 1.2.1 → 1.2.2-dev.47
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/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/middlewares/error-handler.js +6 -0
- package/dist/api/middlewares/error-handler.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +27 -0
- package/dist/{db-subscribers/region.js → api/routes/admin/customer-groups/add-customers-batch.js} +60 -38
- package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -0
- package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +1 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group.js +1 -1
- package/dist/api/routes/admin/customer-groups/index.d.ts +5 -0
- package/dist/api/routes/admin/customer-groups/index.js +7 -0
- package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +38 -0
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js +200 -0
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -0
- package/dist/api/routes/admin/customers/list-customers.js +11 -46
- package/dist/api/routes/admin/customers/list-customers.js.map +1 -1
- package/dist/api/routes/admin/discounts/update-discount.d.ts +2 -2
- package/dist/api/routes/admin/discounts/update-discount.js +3 -3
- package/dist/api/routes/admin/discounts/update-discount.js.map +1 -1
- package/dist/api/routes/store/auth/exists.js +4 -2
- package/dist/api/routes/store/auth/exists.js.map +1 -1
- package/dist/controllers/customers/index.d.ts +4 -0
- package/dist/controllers/customers/index.js +8 -0
- package/dist/controllers/customers/index.js.map +1 -0
- package/dist/controllers/customers/list-customers.d.ts +3 -0
- package/dist/controllers/customers/list-customers.js +96 -0
- package/dist/controllers/customers/list-customers.js.map +1 -0
- package/dist/controllers/list-customers.d.ts +0 -0
- package/dist/controllers/list-customers.js +1 -0
- package/dist/controllers/list-customers.js.map +1 -0
- package/dist/models/customer.js +3 -1
- package/dist/models/customer.js.map +1 -1
- package/dist/repositories/customer-group.d.ts +1 -0
- package/dist/repositories/customer-group.js +24 -0
- package/dist/repositories/customer-group.js.map +1 -1
- package/dist/services/customer-group.d.ts +24 -1
- package/dist/services/customer-group.js +95 -2
- package/dist/services/customer-group.js.map +1 -1
- package/dist/services/customer.d.ts +1 -3
- package/dist/services/customer.js +24 -26
- package/dist/services/customer.js.map +1 -1
- package/dist/services/discount.js +17 -9
- package/dist/services/discount.js.map +1 -1
- package/dist/services/product-collection.js +29 -8
- package/dist/services/product-collection.js.map +1 -1
- package/dist/services/product.js +35 -25
- package/dist/services/product.js.map +1 -1
- package/dist/types/customer-groups.d.ts +5 -1
- package/dist/types/customer-groups.js +25 -0
- package/dist/types/customer-groups.js.map +1 -1
- package/dist/utils/exception-formatter.d.ts +5 -0
- package/dist/utils/exception-formatter.js +29 -0
- package/dist/utils/exception-formatter.js.map +1 -0
- package/package.json +7 -7
- package/yarn-error.log +79 -5
- package/dist/db-subscribers/region.d.ts +0 -6
- package/dist/db-subscribers/region.js.map +0 -1
- package/dist/entity-subscribers/region.d.ts +0 -6
- package/dist/entity-subscribers/region.js +0 -27
- package/dist/entity-subscribers/region.js.map +0 -1
- package/dist/loaders/db-subscribers.d.ts +0 -6
- package/dist/loaders/db-subscribers.js +0 -53
- package/dist/loaders/db-subscribers.js.map +0 -1
- package/dist/subscribers/region.d.ts +0 -14
- package/dist/subscribers/region.js +0 -65
- package/dist/subscribers/region.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-discount.js","sourceRoot":"","sources":["../../../../../src/api/routes/admin/discounts/update-discount.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAwC;AACxC,mDAWwB;AACxB,sBAA+E;AAE/E,0EAAyE;AACzE,
|
|
1
|
+
{"version":3,"file":"update-discount.js","sourceRoot":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BC;AAxBY,0DAAuB"}
|
|
@@ -65,10 +65,12 @@ exports.default = (function (req, res) { return __awaiter(void 0, void 0, void 0
|
|
|
65
65
|
case 1:
|
|
66
66
|
_a.trys.push([1, 3, , 4]);
|
|
67
67
|
customerService = req.scope.resolve("customerService");
|
|
68
|
-
return [4 /*yield*/, customerService.retrieveByEmail(email
|
|
68
|
+
return [4 /*yield*/, customerService.retrieveByEmail(email, {
|
|
69
|
+
select: ["has_account"],
|
|
70
|
+
})];
|
|
69
71
|
case 2:
|
|
70
72
|
customer = _a.sent();
|
|
71
|
-
res.status(200).json({ exists:
|
|
73
|
+
res.status(200).json({ exists: customer.has_account });
|
|
72
74
|
return [3 /*break*/, 4];
|
|
73
75
|
case 3:
|
|
74
76
|
err_1 = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exists.js","sourceRoot":"","sources":["../../../../../src/api/routes/store/auth/exists.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;;;;;;;GAkBG;AACH,mBAAe,UAAO,GAAG,EAAE,GAAG;;;;;gBACpB,KAAK,GAAK,GAAG,CAAC,MAAM,MAAf,CAAe;;;;gBAGpB,eAAe,GACnB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;gBACrB,qBAAM,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,EAAA;;
|
|
1
|
+
{"version":3,"file":"exists.js","sourceRoot":"","sources":["../../../../../src/api/routes/store/auth/exists.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;;;;;;;GAkBG;AACH,mBAAe,UAAO,GAAG,EAAE,GAAG;;;;;gBACpB,KAAK,GAAK,GAAG,CAAC,MAAM,MAAf,CAAe;;;;gBAGpB,eAAe,GACnB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;gBACrB,qBAAM,eAAe,CAAC,eAAe,CAAC,KAAK,EAAE;wBAC5D,MAAM,EAAE,CAAC,aAAa,CAAC;qBACxB,CAAC,EAAA;;gBAFI,QAAQ,GAAG,SAEf;gBACF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;;;;gBAEtD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;;;;;KAE1C,EAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var list_customers_1 = __importDefault(require("./list-customers"));
|
|
7
|
+
exports.default = { listAndCount: list_customers_1.default };
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/controllers/customers/index.ts"],"names":[],"mappings":";;;;;AAAA,oEAA2C;AAC3C,kBAAe,EAAE,YAAY,0BAAA,EAAE,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 (_) 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
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
var lodash_1 = require("lodash");
|
|
56
|
+
var list_customers_1 = require("../../api/routes/admin/customers/list-customers");
|
|
57
|
+
var validator_1 = require("../../utils/validator");
|
|
58
|
+
var listAndCount = function (scope, query, body, context) {
|
|
59
|
+
if (context === void 0) { context = {}; }
|
|
60
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
+
var validatedQueryParams, customerService, expandFields, listConfig, filterableFields, _a, customers, count;
|
|
62
|
+
return __generator(this, function (_b) {
|
|
63
|
+
switch (_b.label) {
|
|
64
|
+
case 0: return [4 /*yield*/, (0, validator_1.validator)(list_customers_1.AdminGetCustomersParams, query)];
|
|
65
|
+
case 1:
|
|
66
|
+
validatedQueryParams = _b.sent();
|
|
67
|
+
customerService = scope.resolve("customerService");
|
|
68
|
+
expandFields = [];
|
|
69
|
+
if (validatedQueryParams.expand) {
|
|
70
|
+
expandFields = validatedQueryParams.expand.split(",");
|
|
71
|
+
}
|
|
72
|
+
listConfig = {
|
|
73
|
+
relations: expandFields,
|
|
74
|
+
skip: validatedQueryParams.offset,
|
|
75
|
+
take: validatedQueryParams.limit,
|
|
76
|
+
};
|
|
77
|
+
filterableFields = (0, lodash_1.omit)(validatedQueryParams, [
|
|
78
|
+
"limit",
|
|
79
|
+
"offset",
|
|
80
|
+
"expand",
|
|
81
|
+
]);
|
|
82
|
+
return [4 /*yield*/, customerService.listAndCount((0, lodash_1.pickBy)(filterableFields, function (val) { return typeof val !== "undefined"; }), listConfig)];
|
|
83
|
+
case 2:
|
|
84
|
+
_a = __read.apply(void 0, [_b.sent(), 2]), customers = _a[0], count = _a[1];
|
|
85
|
+
return [2 /*return*/, {
|
|
86
|
+
customers: customers,
|
|
87
|
+
count: count,
|
|
88
|
+
offset: validatedQueryParams.offset,
|
|
89
|
+
limit: validatedQueryParams.limit,
|
|
90
|
+
}];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
exports.default = listAndCount;
|
|
96
|
+
//# sourceMappingURL=list-customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-customers.js","sourceRoot":"","sources":["../../../src/controllers/customers/list-customers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAqC;AACrC,kFAAyF;AAIzF,mDAAiD;AAGjD,IAAM,YAAY,GAAG,UACnB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,OAAY;IAAZ,wBAAA,EAAA,YAAY;;;;;wBAEiB,qBAAM,IAAA,qBAAS,EAAC,wCAAuB,EAAE,KAAK,CAAC,EAAA;;oBAAtE,oBAAoB,GAAG,SAA+C;oBAEtE,eAAe,GAAoB,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;oBAErE,YAAY,GAAa,EAAE,CAAA;oBAC/B,IAAI,oBAAoB,CAAC,MAAM,EAAE;wBAC/B,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;qBACtD;oBAEK,UAAU,GAAyB;wBACvC,SAAS,EAAE,YAAY;wBACvB,IAAI,EAAE,oBAAoB,CAAC,MAAM;wBACjC,IAAI,EAAE,oBAAoB,CAAC,KAAK;qBACjC,CAAA;oBAEK,gBAAgB,GAAG,IAAA,aAAI,EAAC,oBAAoB,EAAE;wBAClD,OAAO;wBACP,QAAQ;wBACR,QAAQ;qBACT,CAAC,CAAA;oBAEyB,qBAAM,eAAe,CAAC,YAAY,CAC3D,IAAA,eAAM,EAAC,gBAAgB,EAAE,UAAC,GAAG,IAAK,OAAA,OAAO,GAAG,KAAK,WAAW,EAA1B,CAA0B,CAAC,EAC7D,UAAU,CACX,EAAA;;oBAHK,KAAA,sBAAqB,SAG1B,KAAA,EAHM,SAAS,QAAA,EAAE,KAAK,QAAA;oBAKvB,sBAAO;4BACL,SAAS,WAAA;4BACT,KAAK,OAAA;4BACL,MAAM,EAAE,oBAAoB,CAAC,MAAM;4BACnC,KAAK,EAAE,oBAAoB,CAAC,KAAK;yBAClC,EAAA;;;;CACF,CAAA;AAED,kBAAe,YAAY,CAAA"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=list-customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-customers.js","sourceRoot":"","sources":["../../src/controllers/list-customers.ts"],"names":[],"mappings":""}
|
package/dist/models/customer.js
CHANGED
|
@@ -85,7 +85,9 @@ var Customer = /** @class */ (function () {
|
|
|
85
85
|
referencedColumnName: "id",
|
|
86
86
|
},
|
|
87
87
|
}),
|
|
88
|
-
(0, typeorm_1.ManyToMany)(function () { return customer_group_1.CustomerGroup; }, function (cg) { return cg.customers; }, {
|
|
88
|
+
(0, typeorm_1.ManyToMany)(function () { return customer_group_1.CustomerGroup; }, function (cg) { return cg.customers; }, {
|
|
89
|
+
onDelete: "CASCADE",
|
|
90
|
+
}),
|
|
89
91
|
__metadata("design:type", Array)
|
|
90
92
|
], Customer.prototype, "groups", void 0);
|
|
91
93
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../src/models/customer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAcgB;AAChB,6BAA2B;AAC3B,4DAAuE;AAEvE,qCAAmC;AACnC,mDAAgD;AAChD,iCAA+B;AAG/B;IAAA;
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../../src/models/customer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAcgB;AAChB,6BAA2B;AAC3B,4DAAuE;AAEvE,qCAAmC;AACnC,mDAAgD;AAChD,iCAA+B;AAG/B;IAAA;IAyEA,CAAC;IAPS,+BAAY,GAApB;QACE,IAAI,IAAI,CAAC,EAAE,EAAE;YACX,OAAM;SACP;QACD,IAAM,EAAE,GAAG,IAAA,WAAI,GAAE,CAAA;QACjB,IAAI,CAAC,EAAE,GAAG,cAAO,EAAE,CAAE,CAAA;IACvB,CAAC;IAtED;QADC,IAAA,uBAAa,GAAE;;wCACN;IAIV;QAFC,IAAA,eAAK,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACvB,IAAA,gBAAM,GAAE;;2CACI;IAGb;QADC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACT;IAGlB;QADC,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACV;IAIjB;QAFC,IAAA,eAAK,GAAE;QACP,IAAA,gBAAM,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;wDACD;IAI1B;QAFC,IAAA,kBAAQ,EAAC,cAAM,OAAA,iBAAO,EAAP,CAAO,CAAC;QACvB,IAAA,oBAAU,EAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;kCAC1B,iBAAO;qDAAA;IAGxB;QADC,IAAA,mBAAS,EAAC,cAAM,OAAA,iBAAO,EAAP,CAAO,EAAE,UAAC,OAAO,IAAK,OAAA,O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,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACpC;IAGb;QADC,IAAA,sBAAY,GAAE;;;;gDAOd;IAxEU,QAAQ;QADpB,IAAA,gBAAM,GAAE;OACI,QAAQ,CAyEpB;IAAD,eAAC;CAAA,AAzED,IAyEC;AAzEY,4BAAQ;AA2ErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DeleteResult, Repository } from "typeorm";
|
|
2
2
|
import { CustomerGroup } from "../models/customer-group";
|
|
3
3
|
export declare class CustomerGroupRepository extends Repository<CustomerGroup> {
|
|
4
|
+
addCustomers(groupId: string, customerIds: string[]): Promise<CustomerGroup>;
|
|
4
5
|
removeCustomers(groupId: string, customerIds: string[]): Promise<DeleteResult>;
|
|
5
6
|
}
|
|
@@ -65,6 +65,30 @@ var CustomerGroupRepository = /** @class */ (function (_super) {
|
|
|
65
65
|
function CustomerGroupRepository() {
|
|
66
66
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
67
67
|
}
|
|
68
|
+
CustomerGroupRepository.prototype.addCustomers = function (groupId, customerIds) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var customerGroup;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, this.findOne(groupId)];
|
|
74
|
+
case 1:
|
|
75
|
+
customerGroup = _a.sent();
|
|
76
|
+
return [4 /*yield*/, this.createQueryBuilder()
|
|
77
|
+
.insert()
|
|
78
|
+
.into("customer_group_customers")
|
|
79
|
+
.values(customerIds.map(function (id) { return ({
|
|
80
|
+
customer_id: id,
|
|
81
|
+
customer_group_id: groupId,
|
|
82
|
+
}); }))
|
|
83
|
+
.orIgnore()
|
|
84
|
+
.execute()];
|
|
85
|
+
case 2:
|
|
86
|
+
_a.sent();
|
|
87
|
+
return [2 /*return*/, customerGroup];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
68
92
|
CustomerGroupRepository.prototype.removeCustomers = function (groupId, customerIds) {
|
|
69
93
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
94
|
return __generator(this, function (_a) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer-group.js","sourceRoot":"","sources":["../../src/repositories/customer-group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAwE;AACxE,2DAAwD;AAGxD;IAA6C,2CAAyB;IAAtE;;
|
|
1
|
+
{"version":3,"file":"customer-group.js","sourceRoot":"","sources":["../../src/repositories/customer-group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAwE;AACxE,2DAAwD;AAGxD;IAA6C,2CAAyB;IAAtE;;IAmCA,CAAC;IAlCO,8CAAY,GAAlB,UACE,OAAe,EACf,WAAqB;;;;;4BAEC,qBAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAA;;wBAA3C,aAAa,GAAG,SAA2B;wBAEjD,qBAAM,IAAI,CAAC,kBAAkB,EAAE;iCAC5B,MAAM,EAAE;iCACR,IAAI,CAAC,0BAA0B,CAAC;iCAChC,MAAM,CACL,WAAW,CAAC,GAAG,CAAC,UAAC,EAAE,IAAK,OAAA,CAAC;gCACvB,WAAW,EAAE,EAAE;gCACf,iBAAiB,EAAE,OAAO;6BAC3B,CAAC,EAHsB,CAGtB,CAAC,CACJ;iCACA,QAAQ,EAAE;iCACV,OAAO,EAAE,EAAA;;wBAVZ,SAUY,CAAA;wBAEZ,sBAAO,aAA8B,EAAA;;;;KACtC;IAEK,iDAAe,GAArB,UACE,OAAe,EACf,WAAqB;;;;4BAEd,qBAAM,IAAI,CAAC,kBAAkB,EAAE;6BACnC,MAAM,EAAE;6BACR,IAAI,CAAC,0BAA0B,CAAC;6BAChC,KAAK,CAAC;4BACL,iBAAiB,EAAE,OAAO;4BAC1B,WAAW,EAAE,IAAA,YAAE,EAAC,WAAW,CAAC;yBAC7B,CAAC;6BACD,OAAO,EAAE,EAAA;4BAPZ,sBAAO,SAOK,EAAA;;;;KACb;IAlCU,uBAAuB;QADnC,IAAA,0BAAgB,EAAC,8BAAa,CAAC;OACnB,uBAAuB,CAmCnC;IAAD,8BAAC;CAAA,AAnCD,CAA6C,oBAAU,GAmCtD;AAnCY,0DAAuB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseService } from "medusa-interfaces";
|
|
2
2
|
import { DeepPartial, EntityManager } from "typeorm";
|
|
3
|
+
import { CustomerService } from ".";
|
|
3
4
|
import { CustomerGroup } from "..";
|
|
4
5
|
import { CustomerGroupRepository } from "../repositories/customer-group";
|
|
5
6
|
import { FindConfig } from "../types/common";
|
|
@@ -7,11 +8,17 @@ import { CustomerGroupUpdate, FilterableCustomerGroupProps } from "../types/cust
|
|
|
7
8
|
declare type CustomerGroupConstructorProps = {
|
|
8
9
|
manager: EntityManager;
|
|
9
10
|
customerGroupRepository: typeof CustomerGroupRepository;
|
|
11
|
+
customerService: CustomerService;
|
|
10
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Provides layer to manipulate discounts.
|
|
15
|
+
* @implements {BaseService}
|
|
16
|
+
*/
|
|
11
17
|
declare class CustomerGroupService extends BaseService {
|
|
12
18
|
private manager_;
|
|
13
19
|
private customerGroupRepository_;
|
|
14
|
-
|
|
20
|
+
private customerService_;
|
|
21
|
+
constructor({ manager, customerGroupRepository, customerService, }: CustomerGroupConstructorProps);
|
|
15
22
|
withTransaction(transactionManager: EntityManager): CustomerGroupService;
|
|
16
23
|
retrieve(id: string, config?: {}): Promise<CustomerGroup>;
|
|
17
24
|
/**
|
|
@@ -20,11 +27,19 @@ declare class CustomerGroupService extends BaseService {
|
|
|
20
27
|
* @return {Promise} the result of the create operation
|
|
21
28
|
*/
|
|
22
29
|
create(group: DeepPartial<CustomerGroup>): Promise<CustomerGroup>;
|
|
30
|
+
/**
|
|
31
|
+
* Add a batch of customers to a customer group at once
|
|
32
|
+
* @param {string} id id of the customer group to add customers to
|
|
33
|
+
* @param {string[]} customerIds customer id's to add to the group
|
|
34
|
+
* @return {Promise<CustomerGroup>} the customer group after insertion
|
|
35
|
+
*/
|
|
36
|
+
addCustomers(id: string, customerIds: string | string[]): Promise<CustomerGroup>;
|
|
23
37
|
/**
|
|
24
38
|
* Update a customer group.
|
|
25
39
|
*
|
|
26
40
|
* @param {string} customerGroupId - id of the customer group
|
|
27
41
|
* @param {CustomerGroupUpdate} update - customer group partial data
|
|
42
|
+
* @returns resulting customer group
|
|
28
43
|
*/
|
|
29
44
|
update(customerGroupId: string, update: CustomerGroupUpdate): Promise<CustomerGroup[]>;
|
|
30
45
|
/**
|
|
@@ -42,6 +57,14 @@ declare class CustomerGroupService extends BaseService {
|
|
|
42
57
|
* @return {Promise} the result of the find operation
|
|
43
58
|
*/
|
|
44
59
|
list(selector: FilterableCustomerGroupProps | undefined, config: FindConfig<CustomerGroup>): Promise<CustomerGroup[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve a list of customer groups and total count of records that match the query.
|
|
62
|
+
*
|
|
63
|
+
* @param {Object} selector - the query object for find
|
|
64
|
+
* @param {Object} config - the config to be used for find
|
|
65
|
+
* @return {Promise} the result of the find operation
|
|
66
|
+
*/
|
|
67
|
+
listAndCount(selector: FilterableCustomerGroupProps | undefined, config: FindConfig<CustomerGroup>): Promise<[CustomerGroup[], number]>;
|
|
45
68
|
/**
|
|
46
69
|
* Remove list of customers from a customergroup
|
|
47
70
|
*
|
|
@@ -64,13 +64,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
66
66
|
var medusa_interfaces_1 = require("medusa-interfaces");
|
|
67
|
+
var typeorm_1 = require("typeorm");
|
|
68
|
+
var exception_formatter_1 = require("../utils/exception-formatter");
|
|
69
|
+
/**
|
|
70
|
+
* Provides layer to manipulate discounts.
|
|
71
|
+
* @implements {BaseService}
|
|
72
|
+
*/
|
|
67
73
|
var CustomerGroupService = /** @class */ (function (_super) {
|
|
68
74
|
__extends(CustomerGroupService, _super);
|
|
69
75
|
function CustomerGroupService(_a) {
|
|
70
|
-
var manager = _a.manager, customerGroupRepository = _a.customerGroupRepository;
|
|
76
|
+
var manager = _a.manager, customerGroupRepository = _a.customerGroupRepository, customerService = _a.customerService;
|
|
71
77
|
var _this = _super.call(this) || this;
|
|
72
78
|
_this.manager_ = manager;
|
|
73
79
|
_this.customerGroupRepository_ = customerGroupRepository;
|
|
80
|
+
/** @private @const {CustomerGroupService} */
|
|
81
|
+
_this.customerService_ = customerService;
|
|
74
82
|
return _this;
|
|
75
83
|
}
|
|
76
84
|
CustomerGroupService.prototype.withTransaction = function (transactionManager) {
|
|
@@ -80,6 +88,7 @@ var CustomerGroupService = /** @class */ (function (_super) {
|
|
|
80
88
|
var cloned = new CustomerGroupService({
|
|
81
89
|
manager: transactionManager,
|
|
82
90
|
customerGroupRepository: this.customerGroupRepository_,
|
|
91
|
+
customerService: this.customerService_,
|
|
83
92
|
});
|
|
84
93
|
cloned.transactionManager_ = transactionManager;
|
|
85
94
|
return cloned;
|
|
@@ -98,7 +107,7 @@ var CustomerGroupService = /** @class */ (function (_super) {
|
|
|
98
107
|
case 1:
|
|
99
108
|
customerGroup = _a.sent();
|
|
100
109
|
if (!customerGroup) {
|
|
101
|
-
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "CustomerGroup with ".concat(id, " was not found"));
|
|
110
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "CustomerGroup with id ".concat(id, " was not found"));
|
|
102
111
|
}
|
|
103
112
|
return [2 /*return*/, customerGroup];
|
|
104
113
|
}
|
|
@@ -139,11 +148,62 @@ var CustomerGroupService = /** @class */ (function (_super) {
|
|
|
139
148
|
});
|
|
140
149
|
});
|
|
141
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Add a batch of customers to a customer group at once
|
|
153
|
+
* @param {string} id id of the customer group to add customers to
|
|
154
|
+
* @param {string[]} customerIds customer id's to add to the group
|
|
155
|
+
* @return {Promise<CustomerGroup>} the customer group after insertion
|
|
156
|
+
*/
|
|
157
|
+
CustomerGroupService.prototype.addCustomers = function (id, customerIds) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
+
var ids;
|
|
160
|
+
var _this = this;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
if (typeof customerIds === "string") {
|
|
163
|
+
ids = [customerIds];
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
ids = customerIds;
|
|
167
|
+
}
|
|
168
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
169
|
+
var cgRepo;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
cgRepo = manager.getCustomRepository(this.customerGroupRepository_);
|
|
174
|
+
return [4 /*yield*/, cgRepo.addCustomers(id, ids)];
|
|
175
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}); }, function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
179
|
+
var existingCustomers_1, nonExistingCustomers;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
if (!(error.code === "23503")) return [3 /*break*/, 3];
|
|
184
|
+
return [4 /*yield*/, this.retrieve(id)];
|
|
185
|
+
case 1:
|
|
186
|
+
_a.sent();
|
|
187
|
+
return [4 /*yield*/, this.customerService_.list({
|
|
188
|
+
id: ids,
|
|
189
|
+
})];
|
|
190
|
+
case 2:
|
|
191
|
+
existingCustomers_1 = _a.sent();
|
|
192
|
+
nonExistingCustomers = ids.filter(function (cId) { return existingCustomers_1.findIndex(function (el) { return el.id === cId; }) === -1; });
|
|
193
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "The following customer ids do not exist: ".concat(JSON.stringify(nonExistingCustomers.join(", "))));
|
|
194
|
+
case 3: throw (0, exception_formatter_1.formatException)(error);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}); })];
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
142
201
|
/**
|
|
143
202
|
* Update a customer group.
|
|
144
203
|
*
|
|
145
204
|
* @param {string} customerGroupId - id of the customer group
|
|
146
205
|
* @param {CustomerGroupUpdate} update - customer group partial data
|
|
206
|
+
* @returns resulting customer group
|
|
147
207
|
*/
|
|
148
208
|
CustomerGroupService.prototype.update = function (customerGroupId, update) {
|
|
149
209
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -228,6 +288,39 @@ var CustomerGroupService = /** @class */ (function (_super) {
|
|
|
228
288
|
});
|
|
229
289
|
});
|
|
230
290
|
};
|
|
291
|
+
/**
|
|
292
|
+
* Retrieve a list of customer groups and total count of records that match the query.
|
|
293
|
+
*
|
|
294
|
+
* @param {Object} selector - the query object for find
|
|
295
|
+
* @param {Object} config - the config to be used for find
|
|
296
|
+
* @return {Promise} the result of the find operation
|
|
297
|
+
*/
|
|
298
|
+
CustomerGroupService.prototype.listAndCount = function (selector, config) {
|
|
299
|
+
if (selector === void 0) { selector = {}; }
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var cgRepo, q, query, where_1;
|
|
302
|
+
return __generator(this, function (_a) {
|
|
303
|
+
switch (_a.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
cgRepo = this.manager_.getCustomRepository(this.customerGroupRepository_);
|
|
306
|
+
if ("q" in selector) {
|
|
307
|
+
q = selector.q;
|
|
308
|
+
delete selector.q;
|
|
309
|
+
}
|
|
310
|
+
query = this.buildQuery_(selector, config);
|
|
311
|
+
if (q) {
|
|
312
|
+
where_1 = query.where;
|
|
313
|
+
delete where_1.name;
|
|
314
|
+
query.where = function (qb) {
|
|
315
|
+
qb.where(where_1).andWhere([{ name: (0, typeorm_1.ILike)("%".concat(q, "%")) }]);
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return [4 /*yield*/, cgRepo.findAndCount(query)];
|
|
319
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
};
|
|
231
324
|
/**
|
|
232
325
|
* Remove list of customers from a customergroup
|
|
233
326
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer-group.js","sourceRoot":"","sources":["../../src/services/customer-group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;
|
|
1
|
+
{"version":3,"file":"customer-group.js","sourceRoot":"","sources":["../../src/services/customer-group.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA+C;AAC/C,uDAA+C;AAC/C,mCAA+E;AAS/E,oEAA8D;AAQ9D;;;GAGG;AACH;IAAmC,wCAAW;IAO5C,8BAAY,EAIoB;YAH9B,OAAO,aAAA,EACP,uBAAuB,6BAAA,EACvB,eAAe,qBAAA;QAHjB,YAKE,iBAAO,SAQR;QANC,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QAEvB,KAAI,CAAC,wBAAwB,GAAG,uBAAuB,CAAA;QAEvD,6CAA6C;QAC7C,KAAI,CAAC,gBAAgB,GAAG,eAAe,CAAA;;IACzC,CAAC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,EAAE,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAA,eAAK,EAAC,WAAI,CAAC,MAAG,CAAC,EAAE,CAAC,CAAC,CAAA;4BACvD,CAAC,CAAA;yBACF;wBACM,qBAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAA;4BAAvC,sBAAO,SAAgC,EAAA;;;;KACxC;IAED;;;;;;OAMG;IACG,6CAAc,GAApB,UACE,EAAU,EACV,WAA8B;;;;;;wBAExB,MAAM,GAA4B,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CACvE,IAAI,CAAC,wBAAwB,CAC9B,CAAA;wBAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;4BACnC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAA;yBACpB;6BAAM;4BACL,GAAG,GAAG,WAAW,CAAA;yBAClB;wBAEqB,qBAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAA;;wBAAvC,aAAa,GAAG,SAAuB;wBAE7C,qBAAM,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,EAAA;;wBAArC,SAAqC,CAAA;wBAErC,sBAAO,aAAa,EAAA;;;;KACrB;IACH,2BAAC;AAAD,CAAC,AA3QD,CAAmC,+BAAW,GA2Q7C;AAED,kBAAe,oBAAoB,CAAA"}
|
|
@@ -12,12 +12,11 @@ declare class CustomerService extends CustomerService_base implements BaseServic
|
|
|
12
12
|
CREATED: string;
|
|
13
13
|
UPDATED: string;
|
|
14
14
|
};
|
|
15
|
-
constructor({ manager, customerRepository, eventBusService, addressRepository,
|
|
15
|
+
constructor({ manager, customerRepository, eventBusService, addressRepository, }: {
|
|
16
16
|
manager: any;
|
|
17
17
|
customerRepository: any;
|
|
18
18
|
eventBusService: any;
|
|
19
19
|
addressRepository: any;
|
|
20
|
-
customerGroupService: any;
|
|
21
20
|
});
|
|
22
21
|
/** @private @const {EntityManager} */
|
|
23
22
|
private manager_;
|
|
@@ -27,7 +26,6 @@ declare class CustomerService extends CustomerService_base implements BaseServic
|
|
|
27
26
|
private eventBus_;
|
|
28
27
|
/** @private @const {AddressRepository} */
|
|
29
28
|
private addressRepository_;
|
|
30
|
-
customerGroupService_: any;
|
|
31
29
|
withTransaction(transactionManager: any): CustomerService;
|
|
32
30
|
/**
|
|
33
31
|
* Used to validate customer email.
|
|
@@ -109,6 +109,7 @@ var medusa_core_utils_1 = require("medusa-core-utils");
|
|
|
109
109
|
var medusa_interfaces_1 = require("medusa-interfaces");
|
|
110
110
|
var scrypt_kdf_1 = __importDefault(require("scrypt-kdf"));
|
|
111
111
|
var typeorm_1 = require("typeorm");
|
|
112
|
+
var exception_formatter_1 = require("../utils/exception-formatter");
|
|
112
113
|
/**
|
|
113
114
|
* Provides layer to manipulate customers.
|
|
114
115
|
* @implements {BaseService}
|
|
@@ -116,7 +117,7 @@ var typeorm_1 = require("typeorm");
|
|
|
116
117
|
var CustomerService = /** @class */ (function (_super) {
|
|
117
118
|
__extends(CustomerService, _super);
|
|
118
119
|
function CustomerService(_a) {
|
|
119
|
-
var manager = _a.manager, customerRepository = _a.customerRepository, eventBusService = _a.eventBusService, addressRepository = _a.addressRepository
|
|
120
|
+
var manager = _a.manager, customerRepository = _a.customerRepository, eventBusService = _a.eventBusService, addressRepository = _a.addressRepository;
|
|
120
121
|
var _this = _super.call(this) || this;
|
|
121
122
|
/** @private @const {EntityManager} */
|
|
122
123
|
_this.manager_ = manager;
|
|
@@ -126,7 +127,6 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
126
127
|
_this.eventBus_ = eventBusService;
|
|
127
128
|
/** @private @const {AddressRepository} */
|
|
128
129
|
_this.addressRepository_ = addressRepository;
|
|
129
|
-
_this.customerGroupService_ = customerGroupService;
|
|
130
130
|
return _this;
|
|
131
131
|
}
|
|
132
132
|
CustomerService.prototype.withTransaction = function (transactionManager) {
|
|
@@ -148,9 +148,7 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
148
148
|
* @return {string} the validated email
|
|
149
149
|
*/
|
|
150
150
|
CustomerService.prototype.validateEmail_ = function (email) {
|
|
151
|
-
var schema = medusa_core_utils_1.Validator.string()
|
|
152
|
-
.email()
|
|
153
|
-
.required();
|
|
151
|
+
var schema = medusa_core_utils_1.Validator.string().email().required();
|
|
154
152
|
var _a = schema.validate(email), value = _a.value, error = _a.error;
|
|
155
153
|
if (error) {
|
|
156
154
|
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "The email is not valid");
|
|
@@ -476,16 +474,16 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
476
474
|
var _this = this;
|
|
477
475
|
return __generator(this, function (_a) {
|
|
478
476
|
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
479
|
-
var customerRepository, addrRepo, customer, email, password, metadata, billing_address, billing_address_id, groups, rest, address, _a, _b, _c, key, value, _d,
|
|
480
|
-
var e_1,
|
|
481
|
-
return __generator(this, function (
|
|
482
|
-
switch (
|
|
477
|
+
var customerRepository, addrRepo, customer, email, password, metadata, billing_address, billing_address_id, groups, rest, address, _a, _b, _c, key, value, _d, updated;
|
|
478
|
+
var e_1, _e;
|
|
479
|
+
return __generator(this, function (_f) {
|
|
480
|
+
switch (_f.label) {
|
|
483
481
|
case 0:
|
|
484
482
|
customerRepository = manager.getCustomRepository(this.customerRepository_);
|
|
485
483
|
addrRepo = manager.getCustomRepository(this.addressRepository_);
|
|
486
484
|
return [4 /*yield*/, this.retrieve(customerId)];
|
|
487
485
|
case 1:
|
|
488
|
-
customer =
|
|
486
|
+
customer = _f.sent();
|
|
489
487
|
email = update.email, password = update.password, metadata = update.metadata, billing_address = update.billing_address, billing_address_id = update.billing_address_id, groups = update.groups, rest = __rest(update, ["email", "password", "metadata", "billing_address", "billing_address_id", "groups"]);
|
|
490
488
|
if (metadata) {
|
|
491
489
|
customer.metadata = this.setMetadata_(customer, metadata);
|
|
@@ -498,8 +496,8 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
498
496
|
if (!(typeof address !== "undefined")) return [3 /*break*/, 3];
|
|
499
497
|
return [4 /*yield*/, this.updateBillingAddress_(customer, address, addrRepo)];
|
|
500
498
|
case 2:
|
|
501
|
-
|
|
502
|
-
|
|
499
|
+
_f.sent();
|
|
500
|
+
_f.label = 3;
|
|
503
501
|
case 3:
|
|
504
502
|
try {
|
|
505
503
|
for (_a = __values(Object.entries(rest)), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
@@ -510,7 +508,7 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
510
508
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
511
509
|
finally {
|
|
512
510
|
try {
|
|
513
|
-
if (_b && !_b.done && (
|
|
511
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
514
512
|
}
|
|
515
513
|
finally { if (e_1) throw e_1.error; }
|
|
516
514
|
}
|
|
@@ -518,27 +516,27 @@ var CustomerService = /** @class */ (function (_super) {
|
|
|
518
516
|
_d = customer;
|
|
519
517
|
return [4 /*yield*/, this.hashPassword_(password)];
|
|
520
518
|
case 4:
|
|
521
|
-
_d.password_hash =
|
|
522
|
-
|
|
519
|
+
_d.password_hash = _f.sent();
|
|
520
|
+
_f.label = 5;
|
|
523
521
|
case 5:
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
return [4 /*yield*/,
|
|
522
|
+
if (groups) {
|
|
523
|
+
customer.groups = groups;
|
|
524
|
+
}
|
|
525
|
+
return [4 /*yield*/, customerRepository.save(customer)];
|
|
528
526
|
case 6:
|
|
529
|
-
|
|
530
|
-
_g.label = 7;
|
|
531
|
-
case 7: return [4 /*yield*/, customerRepository.save(customer)];
|
|
532
|
-
case 8:
|
|
533
|
-
updated = _g.sent();
|
|
527
|
+
updated = _f.sent();
|
|
534
528
|
return [4 /*yield*/, this.eventBus_
|
|
535
529
|
.withTransaction(manager)
|
|
536
530
|
.emit(CustomerService.Events.UPDATED, updated)];
|
|
537
|
-
case
|
|
538
|
-
|
|
531
|
+
case 7:
|
|
532
|
+
_f.sent();
|
|
539
533
|
return [2 /*return*/, updated];
|
|
540
534
|
}
|
|
541
535
|
});
|
|
536
|
+
}); }, function (error) { return __awaiter(_this, void 0, void 0, function () {
|
|
537
|
+
return __generator(this, function (_a) {
|
|
538
|
+
throw (0, exception_formatter_1.formatException)(error);
|
|
539
|
+
});
|
|
542
540
|
}); })];
|
|
543
541
|
});
|
|
544
542
|
});
|