@labdigital/commercetools-mock 2.37.0 → 2.39.0
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/index.cjs +216 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +216 -80
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
- package/src/ctMock.ts +10 -6
- package/src/helpers.ts +4 -4
- package/src/index.ts +2 -1
- package/src/lib/expandParser.ts +1 -1
- package/src/lib/haversine.test.ts +2 -1
- package/src/lib/password.ts +2 -2
- package/src/lib/predicateParser.ts +1 -1
- package/src/lib/productSearchFilter.test.ts +4 -1
- package/src/lib/projectionSearchFilter.ts +3 -3
- package/src/oauth/helpers.ts +1 -1
- package/src/oauth/server.test.ts +2 -1
- package/src/oauth/server.ts +5 -8
- package/src/oauth/store.ts +1 -1
- package/src/priceSelector.ts +1 -1
- package/src/product-projection-search.ts +4 -2
- package/src/product-search.ts +2 -2
- package/src/projectAPI.ts +4 -4
- package/src/repositories/abstract.ts +20 -3
- package/src/repositories/associate-role.ts +3 -3
- package/src/repositories/attribute-group.ts +3 -3
- package/src/repositories/business-unit.ts +6 -4
- package/src/repositories/cart/actions.ts +6 -7
- package/src/repositories/cart/helpers.ts +1 -1
- package/src/repositories/cart/index.ts +1 -1
- package/src/repositories/cart-discount/actions.ts +14 -5
- package/src/repositories/cart-discount/index.ts +1 -1
- package/src/repositories/category/actions.ts +4 -7
- package/src/repositories/category/index.ts +3 -3
- package/src/repositories/channel.ts +2 -2
- package/src/repositories/custom-object.ts +3 -6
- package/src/repositories/customer/actions.ts +272 -68
- package/src/repositories/customer/index.ts +10 -8
- package/src/repositories/customer-group.ts +2 -2
- package/src/repositories/discount-code/actions.ts +2 -5
- package/src/repositories/discount-code/index.ts +1 -1
- package/src/repositories/extension.ts +3 -3
- package/src/repositories/helpers.ts +4 -2
- package/src/repositories/index.ts +1 -1
- package/src/repositories/inventory-entry/actions.ts +2 -5
- package/src/repositories/inventory-entry/index.ts +1 -1
- package/src/repositories/my-customer.ts +2 -2
- package/src/repositories/order/actions.ts +2 -5
- package/src/repositories/order/index.ts +3 -6
- package/src/repositories/order-edit.ts +3 -2
- package/src/repositories/payment/actions.ts +2 -5
- package/src/repositories/payment/helpers.ts +6 -3
- package/src/repositories/payment/index.ts +3 -2
- package/src/repositories/product/actions.ts +2 -2
- package/src/repositories/product/helpers.ts +4 -4
- package/src/repositories/product/index.ts +3 -2
- package/src/repositories/product-discount.ts +3 -7
- package/src/repositories/product-projection.ts +2 -5
- package/src/repositories/product-selection.ts +3 -7
- package/src/repositories/product-tailoring.ts +3 -7
- package/src/repositories/product-type.ts +7 -11
- package/src/repositories/project.ts +4 -8
- package/src/repositories/quote-request.ts +3 -2
- package/src/repositories/quote.ts +3 -2
- package/src/repositories/review.ts +6 -3
- package/src/repositories/shipping-method/actions.ts +5 -6
- package/src/repositories/shipping-method/helpers.ts +4 -1
- package/src/repositories/shipping-method/index.ts +3 -6
- package/src/repositories/shopping-list/actions.ts +3 -6
- package/src/repositories/shopping-list/index.ts +4 -3
- package/src/repositories/staged-quote.ts +3 -2
- package/src/repositories/standalone-price.ts +3 -7
- package/src/repositories/state.ts +3 -7
- package/src/repositories/store.ts +3 -7
- package/src/repositories/subscription.ts +4 -8
- package/src/repositories/tax-category/actions.ts +2 -1
- package/src/repositories/tax-category/helpers.ts +1 -1
- package/src/repositories/tax-category/index.ts +3 -2
- package/src/repositories/type/actions.ts +2 -1
- package/src/repositories/type/index.ts +3 -2
- package/src/repositories/zone.ts +3 -7
- package/src/services/abstract.ts +2 -2
- package/src/services/associate-roles.test.ts +1 -1
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +1 -1
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +1 -1
- package/src/services/cart-discount.ts +2 -2
- package/src/services/category.ts +2 -2
- package/src/services/channel.ts +2 -2
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +422 -132
- package/src/services/customer.ts +4 -3
- package/src/services/discount-code.ts +2 -2
- package/src/services/extension.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.ts +1 -1
- package/src/services/my-cart.ts +3 -2
- package/src/services/my-customer.ts +4 -3
- package/src/services/my-order.ts +1 -1
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.ts +2 -2
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +1 -1
- package/src/services/product-projection.ts +2 -2
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +2 -2
- package/src/services/project.ts +3 -3
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.ts +2 -2
- package/src/services/shopping-list.test.ts +1 -1
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.ts +2 -2
- package/src/services/store.ts +2 -2
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.ts +2 -2
- package/src/services/zone.ts +2 -2
- package/src/shipping.test.ts +1 -1
- package/src/shipping.ts +3 -3
- package/src/storage/abstract.ts +5 -1
- package/src/storage/in-memory.ts +6 -8
- package/src/types.ts +2 -2
- package/src/validate.ts +2 -2
|
@@ -1,41 +1,55 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
Address,
|
|
2
3
|
BaseAddress,
|
|
3
4
|
Customer,
|
|
4
5
|
CustomerAddAddressAction,
|
|
5
6
|
CustomerAddBillingAddressIdAction,
|
|
6
7
|
CustomerAddShippingAddressIdAction,
|
|
8
|
+
CustomerAddStoreAction,
|
|
7
9
|
CustomerChangeAddressAction,
|
|
8
10
|
CustomerChangeEmailAction,
|
|
11
|
+
CustomerRemoveAddressAction,
|
|
12
|
+
CustomerRemoveBillingAddressIdAction,
|
|
13
|
+
CustomerRemoveShippingAddressIdAction,
|
|
14
|
+
CustomerRemoveStoreAction,
|
|
15
|
+
CustomerSetAddressCustomFieldAction,
|
|
16
|
+
CustomerSetAddressCustomTypeAction,
|
|
9
17
|
CustomerSetAuthenticationModeAction,
|
|
10
18
|
CustomerSetCompanyNameAction,
|
|
11
19
|
CustomerSetCustomFieldAction,
|
|
12
20
|
CustomerSetCustomTypeAction,
|
|
21
|
+
CustomerSetCustomerGroupAction,
|
|
13
22
|
CustomerSetCustomerNumberAction,
|
|
23
|
+
CustomerSetDateOfBirthAction,
|
|
24
|
+
CustomerSetDefaultBillingAddressAction,
|
|
25
|
+
CustomerSetDefaultShippingAddressAction,
|
|
14
26
|
CustomerSetExternalIdAction,
|
|
15
27
|
CustomerSetFirstNameAction,
|
|
16
28
|
CustomerSetKeyAction,
|
|
17
29
|
CustomerSetLastNameAction,
|
|
18
30
|
CustomerSetLocaleAction,
|
|
31
|
+
CustomerSetMiddleNameAction,
|
|
19
32
|
CustomerSetSalutationAction,
|
|
33
|
+
CustomerSetStoresAction,
|
|
34
|
+
CustomerSetTitleAction,
|
|
20
35
|
CustomerSetVatIdAction,
|
|
21
36
|
CustomerUpdateAction,
|
|
22
37
|
InvalidInputError,
|
|
23
38
|
InvalidJsonInputError,
|
|
39
|
+
InvalidOperationError,
|
|
24
40
|
} from "@commercetools/platform-sdk";
|
|
41
|
+
import assert from "node:assert";
|
|
25
42
|
import { CommercetoolsError } from "~src/exceptions";
|
|
26
43
|
import { generateRandomString } from "~src/helpers";
|
|
27
44
|
import { hashPassword } from "~src/lib/password";
|
|
28
45
|
import type { Writable } from "~src/types";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
UpdateHandlerInterface,
|
|
32
|
-
type RepositoryContext,
|
|
33
|
-
} from "../abstract";
|
|
46
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
47
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
34
48
|
import { createAddress, createCustomFields } from "../helpers";
|
|
35
49
|
|
|
36
50
|
export class CustomerUpdateHandler
|
|
37
51
|
extends AbstractUpdateHandler
|
|
38
|
-
implements
|
|
52
|
+
implements UpdateHandlerInterface<Customer, CustomerUpdateAction>
|
|
39
53
|
{
|
|
40
54
|
addAddress(
|
|
41
55
|
_context: RepositoryContext,
|
|
@@ -53,31 +67,15 @@ export class CustomerUpdateHandler
|
|
|
53
67
|
resource: Writable<Customer>,
|
|
54
68
|
{ addressId, addressKey }: CustomerAddBillingAddressIdAction,
|
|
55
69
|
) {
|
|
56
|
-
const address =
|
|
57
|
-
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
a.key != undefined && addressKey != undefined && a.key === addressKey
|
|
63
|
-
);
|
|
64
|
-
});
|
|
70
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
71
|
+
assert(address?.id); // always true since we set required to true
|
|
65
72
|
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
code: "InvalidInput",
|
|
70
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`,
|
|
71
|
-
},
|
|
72
|
-
400,
|
|
73
|
-
);
|
|
73
|
+
if (resource.billingAddressIds === undefined) {
|
|
74
|
+
resource.billingAddressIds = [];
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
resource.billingAddressIds.push(billingAddressId);
|
|
79
|
-
} else if (address) {
|
|
80
|
-
resource.billingAddressIds = [billingAddressId];
|
|
77
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
78
|
+
resource.billingAddressIds.push(address.id);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
|
|
@@ -86,32 +84,25 @@ export class CustomerUpdateHandler
|
|
|
86
84
|
resource: Writable<Customer>,
|
|
87
85
|
{ addressId, addressKey }: CustomerAddShippingAddressIdAction,
|
|
88
86
|
) {
|
|
89
|
-
const address =
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
a.key != undefined && addressKey != undefined && a.key === addressKey
|
|
96
|
-
);
|
|
97
|
-
});
|
|
87
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
88
|
+
assert(address?.id); // always true since we set required to true
|
|
98
89
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
code: "InvalidInput",
|
|
103
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`,
|
|
104
|
-
},
|
|
105
|
-
400,
|
|
106
|
-
);
|
|
90
|
+
if (resource.shippingAddressIds === undefined) {
|
|
91
|
+
resource.shippingAddressIds = [];
|
|
107
92
|
}
|
|
108
93
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
resource.shippingAddressIds.push(shippingAddressId);
|
|
112
|
-
} else if (address) {
|
|
113
|
-
resource.shippingAddressIds = [shippingAddressId];
|
|
94
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
95
|
+
resource.shippingAddressIds.push(address.id);
|
|
114
96
|
}
|
|
97
|
+
return resource;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
addStore(
|
|
101
|
+
context: RepositoryContext,
|
|
102
|
+
resource: Writable<Customer>,
|
|
103
|
+
action: CustomerAddStoreAction,
|
|
104
|
+
) {
|
|
105
|
+
throw new Error("Method not implemented.");
|
|
115
106
|
}
|
|
116
107
|
|
|
117
108
|
changeAddress(
|
|
@@ -119,25 +110,12 @@ export class CustomerUpdateHandler
|
|
|
119
110
|
resource: Writable<Customer>,
|
|
120
111
|
{ addressId, addressKey, address }: CustomerChangeAddressAction,
|
|
121
112
|
) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
a.key != undefined && addressKey != undefined && a.key === addressKey
|
|
129
|
-
);
|
|
130
|
-
});
|
|
113
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
114
|
+
assert(current?.id); // always true since we set required to true
|
|
131
115
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
code: "InvalidInput",
|
|
136
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`,
|
|
137
|
-
},
|
|
138
|
-
400,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
116
|
+
const oldAddressIndex = resource.addresses.findIndex(
|
|
117
|
+
(a) => a.id === current.id,
|
|
118
|
+
);
|
|
141
119
|
|
|
142
120
|
const newAddress = createAddress(
|
|
143
121
|
address,
|
|
@@ -161,6 +139,85 @@ export class CustomerUpdateHandler
|
|
|
161
139
|
resource.email = email;
|
|
162
140
|
}
|
|
163
141
|
|
|
142
|
+
removeAddress(
|
|
143
|
+
context: RepositoryContext,
|
|
144
|
+
resource: Writable<Customer>,
|
|
145
|
+
action: CustomerRemoveAddressAction,
|
|
146
|
+
) {
|
|
147
|
+
const address = this._findAddress(
|
|
148
|
+
resource,
|
|
149
|
+
action.addressId,
|
|
150
|
+
action.addressKey,
|
|
151
|
+
true,
|
|
152
|
+
);
|
|
153
|
+
assert(address?.id); // always true since we set required to true
|
|
154
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
removeBillingAddressId(
|
|
158
|
+
context: RepositoryContext,
|
|
159
|
+
resource: Writable<Customer>,
|
|
160
|
+
action: CustomerRemoveBillingAddressIdAction,
|
|
161
|
+
) {
|
|
162
|
+
const address = this._findAddress(
|
|
163
|
+
resource,
|
|
164
|
+
action.addressId,
|
|
165
|
+
action.addressKey,
|
|
166
|
+
true,
|
|
167
|
+
);
|
|
168
|
+
assert(address?.id); // always true since we set required to true
|
|
169
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter(
|
|
170
|
+
(id) => id !== address.id,
|
|
171
|
+
);
|
|
172
|
+
if (resource.defaultBillingAddressId === address.id) {
|
|
173
|
+
resource.defaultBillingAddressId = undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
removeShippingAddressId(
|
|
178
|
+
context: RepositoryContext,
|
|
179
|
+
resource: Writable<Customer>,
|
|
180
|
+
action: CustomerRemoveShippingAddressIdAction,
|
|
181
|
+
) {
|
|
182
|
+
const address = this._findAddress(
|
|
183
|
+
resource,
|
|
184
|
+
action.addressId,
|
|
185
|
+
action.addressKey,
|
|
186
|
+
true,
|
|
187
|
+
);
|
|
188
|
+
assert(address?.id); // always true since we set required to true
|
|
189
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter(
|
|
190
|
+
(id) => id !== address.id,
|
|
191
|
+
);
|
|
192
|
+
if (resource.defaultShippingAddressId === address.id) {
|
|
193
|
+
resource.defaultShippingAddressId = undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
removeStore(
|
|
198
|
+
context: RepositoryContext,
|
|
199
|
+
resource: Writable<Customer>,
|
|
200
|
+
action: CustomerRemoveStoreAction,
|
|
201
|
+
) {
|
|
202
|
+
throw new Error("Method not implemented.");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setAddressCustomField(
|
|
206
|
+
context: RepositoryContext,
|
|
207
|
+
resource: Writable<Customer>,
|
|
208
|
+
action: CustomerSetAddressCustomFieldAction,
|
|
209
|
+
) {
|
|
210
|
+
throw new Error("Method not implemented.");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setAddressCustomType(
|
|
214
|
+
context: RepositoryContext,
|
|
215
|
+
resource: Writable<Customer>,
|
|
216
|
+
action: CustomerSetAddressCustomTypeAction,
|
|
217
|
+
) {
|
|
218
|
+
throw new Error("Method not implemented.");
|
|
219
|
+
}
|
|
220
|
+
|
|
164
221
|
setAuthenticationMode(
|
|
165
222
|
_context: RepositoryContext,
|
|
166
223
|
resource: Writable<Customer>,
|
|
@@ -202,6 +259,32 @@ export class CustomerUpdateHandler
|
|
|
202
259
|
resource.companyName = companyName;
|
|
203
260
|
}
|
|
204
261
|
|
|
262
|
+
setCustomerGroup(
|
|
263
|
+
context: RepositoryContext,
|
|
264
|
+
resource: Writable<Customer>,
|
|
265
|
+
action: CustomerSetCustomerGroupAction,
|
|
266
|
+
) {
|
|
267
|
+
if (!action.customerGroup) {
|
|
268
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
269
|
+
{
|
|
270
|
+
code: "InvalidOperation",
|
|
271
|
+
message: "CustomerGroup is required.",
|
|
272
|
+
},
|
|
273
|
+
400,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const group = this._storage.getByResourceIdentifier<"customer-group">(
|
|
278
|
+
context.projectKey,
|
|
279
|
+
action.customerGroup,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
resource.customerGroup = {
|
|
283
|
+
typeId: "customer-group",
|
|
284
|
+
id: group.id,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
205
288
|
setCustomerNumber(
|
|
206
289
|
_context: RepositoryContext,
|
|
207
290
|
resource: Writable<Customer>,
|
|
@@ -242,6 +325,58 @@ export class CustomerUpdateHandler
|
|
|
242
325
|
}
|
|
243
326
|
}
|
|
244
327
|
|
|
328
|
+
setDateOfBirth(
|
|
329
|
+
context: RepositoryContext,
|
|
330
|
+
resource: Writable<Customer>,
|
|
331
|
+
action: CustomerSetDateOfBirthAction,
|
|
332
|
+
) {
|
|
333
|
+
resource.dateOfBirth = action.dateOfBirth;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
setDefaultBillingAddress(
|
|
337
|
+
context: RepositoryContext,
|
|
338
|
+
resource: Writable<Customer>,
|
|
339
|
+
action: CustomerSetDefaultBillingAddressAction,
|
|
340
|
+
) {
|
|
341
|
+
const address = this._findAddress(
|
|
342
|
+
resource,
|
|
343
|
+
action.addressId,
|
|
344
|
+
action.addressKey,
|
|
345
|
+
true,
|
|
346
|
+
);
|
|
347
|
+
assert(address?.id); // always true since we set required to true
|
|
348
|
+
|
|
349
|
+
resource.defaultBillingAddressId = address.id;
|
|
350
|
+
if (resource.billingAddressIds === undefined) {
|
|
351
|
+
resource.billingAddressIds = [];
|
|
352
|
+
}
|
|
353
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
354
|
+
resource.billingAddressIds.push(address.id);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
setDefaultShippingAddress(
|
|
359
|
+
context: RepositoryContext,
|
|
360
|
+
resource: Writable<Customer>,
|
|
361
|
+
action: CustomerSetDefaultShippingAddressAction,
|
|
362
|
+
) {
|
|
363
|
+
const address = this._findAddress(
|
|
364
|
+
resource,
|
|
365
|
+
action.addressId,
|
|
366
|
+
action.addressKey,
|
|
367
|
+
true,
|
|
368
|
+
);
|
|
369
|
+
assert(address?.id); // always true since we set required to true
|
|
370
|
+
|
|
371
|
+
resource.defaultShippingAddressId = address.id;
|
|
372
|
+
if (resource.shippingAddressIds === undefined) {
|
|
373
|
+
resource.shippingAddressIds = [];
|
|
374
|
+
}
|
|
375
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
376
|
+
resource.shippingAddressIds.push(address.id);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
245
380
|
setExternalId(
|
|
246
381
|
_context: RepositoryContext,
|
|
247
382
|
resource: Writable<Customer>,
|
|
@@ -282,6 +417,14 @@ export class CustomerUpdateHandler
|
|
|
282
417
|
resource.locale = locale;
|
|
283
418
|
}
|
|
284
419
|
|
|
420
|
+
setMiddleName(
|
|
421
|
+
context: RepositoryContext,
|
|
422
|
+
resource: Writable<Customer>,
|
|
423
|
+
action: CustomerSetMiddleNameAction,
|
|
424
|
+
) {
|
|
425
|
+
resource.middleName = action.middleName;
|
|
426
|
+
}
|
|
427
|
+
|
|
285
428
|
setSalutation(
|
|
286
429
|
_context: RepositoryContext,
|
|
287
430
|
resource: Writable<Customer>,
|
|
@@ -290,6 +433,22 @@ export class CustomerUpdateHandler
|
|
|
290
433
|
resource.salutation = salutation;
|
|
291
434
|
}
|
|
292
435
|
|
|
436
|
+
setStores(
|
|
437
|
+
context: RepositoryContext,
|
|
438
|
+
resource: Writable<Customer>,
|
|
439
|
+
action: CustomerSetStoresAction,
|
|
440
|
+
) {
|
|
441
|
+
throw new Error("Method not implemented.");
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
setTitle(
|
|
445
|
+
context: RepositoryContext,
|
|
446
|
+
resource: Writable<Customer>,
|
|
447
|
+
action: CustomerSetTitleAction,
|
|
448
|
+
) {
|
|
449
|
+
resource.title = action.title;
|
|
450
|
+
}
|
|
451
|
+
|
|
293
452
|
setVatId(
|
|
294
453
|
_context: RepositoryContext,
|
|
295
454
|
resource: Writable<Customer>,
|
|
@@ -297,4 +456,49 @@ export class CustomerUpdateHandler
|
|
|
297
456
|
) {
|
|
298
457
|
resource.vatId = vatId;
|
|
299
458
|
}
|
|
459
|
+
|
|
460
|
+
private _findAddress(
|
|
461
|
+
resource: Writable<Customer>,
|
|
462
|
+
addressId: string | undefined,
|
|
463
|
+
addressKey: string | undefined,
|
|
464
|
+
required: boolean = false,
|
|
465
|
+
): Address | undefined {
|
|
466
|
+
if (addressKey) {
|
|
467
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
468
|
+
if (!address) {
|
|
469
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
470
|
+
{
|
|
471
|
+
code: "InvalidOperation",
|
|
472
|
+
message: `Customer does not contain an address with the key ${addressKey}.`,
|
|
473
|
+
},
|
|
474
|
+
400,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
return address;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (addressId) {
|
|
481
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
482
|
+
if (!address) {
|
|
483
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
484
|
+
{
|
|
485
|
+
code: "InvalidOperation",
|
|
486
|
+
message: `Customer does not contain an address with the id ${addressId}.`,
|
|
487
|
+
},
|
|
488
|
+
400,
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
return address;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (required) {
|
|
495
|
+
throw new CommercetoolsError<InvalidOperationError>(
|
|
496
|
+
{
|
|
497
|
+
code: "InvalidOperation",
|
|
498
|
+
message: "One of address 'addressId' or 'addressKey' is required.",
|
|
499
|
+
},
|
|
500
|
+
400,
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
300
504
|
}
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
hashPassword,
|
|
19
19
|
validatePasswordResetToken,
|
|
20
20
|
} from "~src/lib/password";
|
|
21
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
22
|
-
import { Writable } from "~src/types";
|
|
21
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
22
|
+
import type { Writable } from "~src/types";
|
|
23
23
|
import {
|
|
24
24
|
AbstractResourceRepository,
|
|
25
25
|
type RepositoryContext,
|
|
@@ -85,12 +85,14 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {
|
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
const defaultBillingAddressId =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
const defaultBillingAddressId =
|
|
89
|
+
draft.defaultBillingAddress !== undefined
|
|
90
|
+
? lookupAdressId(addresses, draft.defaultBillingAddress)
|
|
91
|
+
: undefined;
|
|
92
|
+
const defaultShippingAddressId =
|
|
93
|
+
draft.defaultShippingAddress !== undefined
|
|
94
|
+
? lookupAdressId(addresses, draft.defaultShippingAddress)
|
|
95
|
+
: undefined;
|
|
94
96
|
const shippingAddressIds =
|
|
95
97
|
draft.shippingAddresses?.map((addressId) =>
|
|
96
98
|
lookupAdressId(addresses, addressId),
|
|
@@ -8,12 +8,12 @@ import type {
|
|
|
8
8
|
CustomerGroupUpdateAction,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import { getBaseResourceProperties } from "../helpers";
|
|
11
|
-
import { AbstractStorage } from "../storage/abstract";
|
|
11
|
+
import type { AbstractStorage } from "../storage/abstract";
|
|
12
12
|
import type { Writable } from "../types";
|
|
13
|
+
import type { UpdateHandlerInterface } from "./abstract";
|
|
13
14
|
import {
|
|
14
15
|
AbstractResourceRepository,
|
|
15
16
|
AbstractUpdateHandler,
|
|
16
|
-
UpdateHandlerInterface,
|
|
17
17
|
type RepositoryContext,
|
|
18
18
|
} from "./abstract";
|
|
19
19
|
import { createCustomFields } from "./helpers";
|
|
@@ -16,11 +16,8 @@ import type {
|
|
|
16
16
|
DiscountCodeUpdateAction,
|
|
17
17
|
} from "@commercetools/platform-sdk";
|
|
18
18
|
import type { Writable } from "~src/types";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
UpdateHandlerInterface,
|
|
22
|
-
type RepositoryContext,
|
|
23
|
-
} from "../abstract";
|
|
19
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
20
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
24
21
|
import { createCustomFields } from "../helpers";
|
|
25
22
|
|
|
26
23
|
export class DiscountCodeUpdateHandler
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
DiscountCodeDraft,
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
6
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
7
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
7
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
8
8
|
import {
|
|
9
9
|
AbstractResourceRepository,
|
|
10
10
|
type RepositoryContext,
|
|
@@ -7,14 +7,14 @@ import type {
|
|
|
7
7
|
ExtensionSetTimeoutInMsAction,
|
|
8
8
|
ExtensionUpdateAction,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
|
-
import { AbstractStorage } from "~src/storage";
|
|
10
|
+
import type { AbstractStorage } from "~src/storage";
|
|
11
11
|
import { getBaseResourceProperties } from "../helpers";
|
|
12
12
|
import { maskSecretValue } from "../lib/masking";
|
|
13
13
|
import type { Writable } from "../types";
|
|
14
|
+
import type { UpdateHandlerInterface } from "./abstract";
|
|
14
15
|
import {
|
|
15
16
|
AbstractResourceRepository,
|
|
16
17
|
AbstractUpdateHandler,
|
|
17
|
-
UpdateHandlerInterface,
|
|
18
18
|
type RepositoryContext,
|
|
19
19
|
} from "./abstract";
|
|
20
20
|
|
|
@@ -49,7 +49,7 @@ export class ExtensionRepository extends AbstractResourceRepository<"extension">
|
|
|
49
49
|
extension,
|
|
50
50
|
"destination.authentication.headerValue",
|
|
51
51
|
);
|
|
52
|
-
} else if (extension.destination.type
|
|
52
|
+
} else if (extension.destination.type === "AWSLambda") {
|
|
53
53
|
return maskSecretValue(resource, "destination.accessSecret");
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AssociateRoleReference,
|
|
3
3
|
BusinessUnitKeyReference,
|
|
4
4
|
BusinessUnitReference,
|
|
5
5
|
BusinessUnitResourceIdentifier,
|
|
6
6
|
RoundingMode,
|
|
7
|
+
} from "@commercetools/platform-sdk";
|
|
8
|
+
import {
|
|
7
9
|
type Address,
|
|
8
10
|
type Associate,
|
|
9
11
|
type AssociateDraft,
|
|
@@ -34,7 +36,7 @@ import { Decimal } from "decimal.js/decimal";
|
|
|
34
36
|
import type { Request } from "express";
|
|
35
37
|
import { v4 as uuidv4 } from "uuid";
|
|
36
38
|
import { CommercetoolsError } from "~src/exceptions";
|
|
37
|
-
import { AbstractStorage } from "../storage";
|
|
39
|
+
import type { AbstractStorage } from "../storage";
|
|
38
40
|
import { type RepositoryContext } from "./abstract";
|
|
39
41
|
|
|
40
42
|
export const createAddress = (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProductTailoringRepository } from "~src/repositories/product-tailoring";
|
|
2
|
-
import { AbstractStorage } from "../storage";
|
|
2
|
+
import type { AbstractStorage } from "../storage";
|
|
3
3
|
import { AssociateRoleRepository } from "./associate-role";
|
|
4
4
|
import { AttributeGroupRepository } from "./attribute-group";
|
|
5
5
|
import { BusinessUnitRepository } from "./business-unit";
|
|
@@ -8,11 +8,8 @@ import type {
|
|
|
8
8
|
InventoryEntryUpdateAction,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import type { Writable } from "~src/types";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
UpdateHandlerInterface,
|
|
14
|
-
type RepositoryContext,
|
|
15
|
-
} from "../abstract";
|
|
11
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
12
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
16
13
|
|
|
17
14
|
export class InventoryEntryUpdateHandler
|
|
18
15
|
extends AbstractUpdateHandler
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
InventoryEntryDraft,
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
5
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
6
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
6
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
7
7
|
import {
|
|
8
8
|
AbstractResourceRepository,
|
|
9
9
|
type RepositoryContext,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Customer,
|
|
3
3
|
InvalidCurrentPasswordError,
|
|
4
4
|
MyCustomerChangePassword,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@commercetools/platform-sdk";
|
|
8
8
|
import { CommercetoolsError } from "~src/exceptions";
|
|
9
9
|
import { hashPassword, validateEmailVerifyToken } from "../lib/password";
|
|
10
|
-
import { Writable } from "../types";
|
|
10
|
+
import type { Writable } from "../types";
|
|
11
11
|
import { type RepositoryContext } from "./abstract";
|
|
12
12
|
import { CustomerRepository } from "./customer";
|
|
13
13
|
|
|
@@ -29,11 +29,8 @@ import type {
|
|
|
29
29
|
import assert from "assert";
|
|
30
30
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
31
31
|
import type { Writable } from "~src/types";
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
RepositoryContext,
|
|
35
|
-
UpdateHandlerInterface,
|
|
36
|
-
} from "../abstract";
|
|
32
|
+
import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
|
|
33
|
+
import { AbstractUpdateHandler } from "../abstract";
|
|
37
34
|
import { createAddress } from "../helpers";
|
|
38
35
|
|
|
39
36
|
export class OrderUpdateHandler
|
|
@@ -16,12 +16,9 @@ import type {
|
|
|
16
16
|
import assert from "assert";
|
|
17
17
|
import { CommercetoolsError } from "~src/exceptions";
|
|
18
18
|
import { generateRandomString, getBaseResourceProperties } from "~src/helpers";
|
|
19
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
RepositoryContext,
|
|
23
|
-
type QueryParams,
|
|
24
|
-
} from "../abstract";
|
|
19
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
20
|
+
import type { RepositoryContext } from "../abstract";
|
|
21
|
+
import { AbstractResourceRepository, type QueryParams } from "../abstract";
|
|
25
22
|
import {
|
|
26
23
|
createAddress,
|
|
27
24
|
createCentPrecisionMoney,
|
|
@@ -3,9 +3,10 @@ import type {
|
|
|
3
3
|
OrderEditDraft,
|
|
4
4
|
OrderEditResult,
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
|
-
import { AbstractStorage } from "~src/storage";
|
|
6
|
+
import type { AbstractStorage } from "~src/storage";
|
|
7
7
|
import { getBaseResourceProperties } from "../helpers";
|
|
8
|
-
import {
|
|
8
|
+
import type { RepositoryContext } from "./abstract";
|
|
9
|
+
import { AbstractResourceRepository } from "./abstract";
|
|
9
10
|
|
|
10
11
|
export class OrderEditRepository extends AbstractResourceRepository<"order-edit"> {
|
|
11
12
|
constructor(storage: AbstractStorage) {
|
|
@@ -26,11 +26,8 @@ import type {
|
|
|
26
26
|
Transaction,
|
|
27
27
|
} from "@commercetools/platform-sdk";
|
|
28
28
|
import type { Writable } from "~src/types";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
RepositoryContext,
|
|
32
|
-
UpdateHandlerInterface,
|
|
33
|
-
} from "../abstract";
|
|
29
|
+
import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
|
|
30
|
+
import { AbstractUpdateHandler } from "../abstract";
|
|
34
31
|
import {
|
|
35
32
|
createCentPrecisionMoney,
|
|
36
33
|
createCustomFields,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionDraft,
|
|
4
|
+
} from "@commercetools/platform-sdk";
|
|
2
5
|
import { v4 as uuidv4 } from "uuid";
|
|
3
|
-
import { AbstractStorage } from "~src/storage";
|
|
4
|
-
import { RepositoryContext } from "../abstract";
|
|
6
|
+
import type { AbstractStorage } from "~src/storage";
|
|
7
|
+
import type { RepositoryContext } from "../abstract";
|
|
5
8
|
import { createCentPrecisionMoney, createCustomFields } from "../helpers";
|
|
6
9
|
|
|
7
10
|
export const transactionFromTransactionDraft = (
|