@labdigital/commercetools-mock 0.5.23 → 0.6.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.
- package/dist/commercetools-mock.cjs.development.js +364 -298
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +364 -298
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/abstract.d.ts +13 -9
- package/dist/repositories/cart-discount.d.ts +3 -3
- package/dist/repositories/cart.d.ts +13 -13
- package/dist/repositories/category.d.ts +11 -11
- package/dist/repositories/channel.d.ts +2 -2
- package/dist/repositories/custom-object.d.ts +3 -3
- package/dist/repositories/customer-group.d.ts +4 -4
- package/dist/repositories/customer.d.ts +4 -4
- package/dist/repositories/discount-code.d.ts +3 -3
- package/dist/repositories/extension.d.ts +3 -3
- package/dist/repositories/helpers.d.ts +3 -0
- package/dist/repositories/inventory-entry.d.ts +7 -7
- package/dist/repositories/my-order.d.ts +6 -0
- package/dist/repositories/order.d.ts +18 -17
- package/dist/repositories/payment.d.ts +8 -8
- package/dist/repositories/product-projection.d.ts +3 -3
- package/dist/repositories/product-type.d.ts +5 -5
- package/dist/repositories/product.d.ts +4 -4
- package/dist/repositories/project.d.ts +4 -4
- package/dist/repositories/shipping-method.d.ts +3 -3
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +3 -3
- package/dist/repositories/store.d.ts +4 -4
- package/dist/repositories/subscription.d.ts +2 -2
- package/dist/repositories/tax-category.d.ts +4 -4
- package/dist/repositories/type.d.ts +3 -3
- package/dist/repositories/zone.d.ts +3 -3
- package/dist/services/my-order.d.ts +2 -2
- package/package.json +5 -2
- package/src/ctMock.ts +6 -0
- package/src/repositories/abstract.ts +37 -17
- package/src/repositories/cart-discount.ts +11 -11
- package/src/repositories/cart.ts +88 -36
- package/src/repositories/category.ts +17 -13
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +16 -8
- package/src/repositories/customer-group.ts +5 -5
- package/src/repositories/customer.ts +13 -7
- package/src/repositories/discount-code.ts +14 -14
- package/src/repositories/extension.ts +12 -8
- package/src/repositories/helpers.ts +9 -0
- package/src/repositories/inventory-entry.ts +17 -10
- package/src/repositories/my-order.ts +19 -0
- package/src/repositories/order.test.ts +79 -3
- package/src/repositories/order.ts +77 -37
- package/src/repositories/payment.ts +21 -17
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-type.ts +14 -10
- package/src/repositories/product.ts +5 -5
- package/src/repositories/project.ts +21 -17
- package/src/repositories/shipping-method.ts +27 -20
- package/src/repositories/shopping-list.ts +10 -6
- package/src/repositories/state.ts +13 -9
- package/src/repositories/store.ts +18 -14
- package/src/repositories/subscription.ts +3 -3
- package/src/repositories/tax-category.ts +16 -12
- package/src/repositories/type.ts +15 -11
- package/src/repositories/zone.ts +13 -9
- package/src/services/abstract.ts +21 -10
- package/src/services/cart.test.ts +48 -8
- package/src/services/cart.ts +17 -11
- package/src/services/custom-object.ts +8 -4
- package/src/services/customer.ts +5 -2
- package/src/services/my-customer.ts +7 -3
- package/src/services/my-order.ts +3 -3
- package/src/services/order.ts +3 -2
- package/src/services/product-projection.ts +2 -1
- package/src/services/product-type.ts +2 -1
- package/src/services/project.ts +4 -3
- package/src/services/store.ts +2 -1
- package/src/services/tax-category.ts +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
2
|
import {
|
|
3
3
|
Cart,
|
|
4
|
+
CartReference,
|
|
4
5
|
CustomLineItem,
|
|
5
6
|
CustomLineItemDraft,
|
|
6
7
|
GeneralError,
|
|
@@ -20,8 +21,6 @@ import {
|
|
|
20
21
|
OrderSetOrderNumberAction,
|
|
21
22
|
OrderSetShippingAddressAction,
|
|
22
23
|
OrderSetStoreAction,
|
|
23
|
-
OrderState,
|
|
24
|
-
OrderStateTransitionMessage,
|
|
25
24
|
OrderTransitionStateAction,
|
|
26
25
|
Product,
|
|
27
26
|
ProductPagedQueryResponse,
|
|
@@ -30,7 +29,11 @@ import {
|
|
|
30
29
|
State,
|
|
31
30
|
Store,
|
|
32
31
|
} from '@commercetools/platform-sdk'
|
|
33
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
AbstractResourceRepository,
|
|
34
|
+
QueryParams,
|
|
35
|
+
RepositoryContext,
|
|
36
|
+
} from './abstract'
|
|
34
37
|
import {
|
|
35
38
|
createCustomFields,
|
|
36
39
|
createPrice,
|
|
@@ -46,12 +49,26 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
46
49
|
return 'order'
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
create(
|
|
52
|
+
create(context: RepositoryContext, draft: OrderFromCartDraft): Order {
|
|
50
53
|
assert(draft.cart, 'draft.cart is missing')
|
|
54
|
+
return this.createFromCart(
|
|
55
|
+
context,
|
|
56
|
+
{
|
|
57
|
+
id: draft.cart.id!,
|
|
58
|
+
typeId: 'cart',
|
|
59
|
+
},
|
|
60
|
+
draft.orderNumber
|
|
61
|
+
)
|
|
62
|
+
}
|
|
51
63
|
|
|
64
|
+
createFromCart(
|
|
65
|
+
context: RepositoryContext,
|
|
66
|
+
cartReference: CartReference,
|
|
67
|
+
orderNumber?: string
|
|
68
|
+
) {
|
|
52
69
|
const cart = this._storage.getByResourceIdentifier(
|
|
53
|
-
projectKey,
|
|
54
|
-
|
|
70
|
+
context.projectKey,
|
|
71
|
+
cartReference
|
|
55
72
|
) as Cart | null
|
|
56
73
|
if (!cart) {
|
|
57
74
|
throw new Error('Cannot find cart')
|
|
@@ -59,7 +76,8 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
59
76
|
|
|
60
77
|
const resource: Order = {
|
|
61
78
|
...getBaseResourceProperties(),
|
|
62
|
-
orderNumber
|
|
79
|
+
orderNumber,
|
|
80
|
+
cart: cartReference,
|
|
63
81
|
orderState: 'Open',
|
|
64
82
|
lineItems: [],
|
|
65
83
|
customLineItems: [],
|
|
@@ -67,13 +85,19 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
67
85
|
refusedGifts: [],
|
|
68
86
|
origin: 'Customer',
|
|
69
87
|
syncInfo: [],
|
|
88
|
+
store: context.storeKey
|
|
89
|
+
? {
|
|
90
|
+
key: context.storeKey,
|
|
91
|
+
typeId: 'store',
|
|
92
|
+
}
|
|
93
|
+
: undefined,
|
|
70
94
|
lastMessageSequenceNumber: 0,
|
|
71
95
|
}
|
|
72
|
-
this.save(
|
|
96
|
+
this.save(context, resource)
|
|
73
97
|
return resource
|
|
74
98
|
}
|
|
75
99
|
|
|
76
|
-
import(
|
|
100
|
+
import(context: RepositoryContext, draft: OrderImportDraft): Order {
|
|
77
101
|
// TODO: Check if order with given orderNumber already exists
|
|
78
102
|
assert(this, 'OrderRepository not valid')
|
|
79
103
|
const resource: Order = {
|
|
@@ -82,7 +106,11 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
82
106
|
billingAddress: draft.billingAddress,
|
|
83
107
|
shippingAddress: draft.shippingAddress,
|
|
84
108
|
|
|
85
|
-
custom: createCustomFields(
|
|
109
|
+
custom: createCustomFields(
|
|
110
|
+
draft.custom,
|
|
111
|
+
context.projectKey,
|
|
112
|
+
this._storage
|
|
113
|
+
),
|
|
86
114
|
customerEmail: draft.customerEmail,
|
|
87
115
|
lastMessageSequenceNumber: 0,
|
|
88
116
|
orderNumber: draft.orderNumber,
|
|
@@ -90,16 +118,20 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
90
118
|
origin: draft.origin || 'Customer',
|
|
91
119
|
paymentState: draft.paymentState,
|
|
92
120
|
refusedGifts: [],
|
|
93
|
-
store: resolveStoreReference(
|
|
121
|
+
store: resolveStoreReference(
|
|
122
|
+
draft.store,
|
|
123
|
+
context.projectKey,
|
|
124
|
+
this._storage
|
|
125
|
+
),
|
|
94
126
|
syncInfo: [],
|
|
95
127
|
|
|
96
128
|
lineItems:
|
|
97
129
|
draft.lineItems?.map(item =>
|
|
98
|
-
this.lineItemFromImportDraft.bind(this)(
|
|
130
|
+
this.lineItemFromImportDraft.bind(this)(context, item)
|
|
99
131
|
) || [],
|
|
100
132
|
customLineItems:
|
|
101
133
|
draft.customLineItems?.map(item =>
|
|
102
|
-
this.customLineItemFromImportDraft.bind(this)(
|
|
134
|
+
this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
103
135
|
) || [],
|
|
104
136
|
|
|
105
137
|
totalPrice: {
|
|
@@ -108,12 +140,12 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
108
140
|
fractionDigits: 2,
|
|
109
141
|
},
|
|
110
142
|
}
|
|
111
|
-
this.save(
|
|
143
|
+
this.save(context, resource)
|
|
112
144
|
return resource
|
|
113
145
|
}
|
|
114
146
|
|
|
115
147
|
private lineItemFromImportDraft(
|
|
116
|
-
|
|
148
|
+
context: RepositoryContext,
|
|
117
149
|
draft: LineItemImportDraft
|
|
118
150
|
): LineItem {
|
|
119
151
|
let product: Product
|
|
@@ -125,7 +157,7 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
125
157
|
sku: draft.variant.sku,
|
|
126
158
|
}
|
|
127
159
|
|
|
128
|
-
var items = this._storage.query(projectKey, 'product', {
|
|
160
|
+
var items = this._storage.query(context.projectKey, 'product', {
|
|
129
161
|
where: [
|
|
130
162
|
`masterData(current(masterVariant(sku="${draft.variant.sku}"))) or masterData(current(variants(sku="${draft.variant.sku}")))`,
|
|
131
163
|
],
|
|
@@ -155,7 +187,11 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
155
187
|
|
|
156
188
|
const lineItem: LineItem = {
|
|
157
189
|
...getBaseResourceProperties(),
|
|
158
|
-
custom: createCustomFields(
|
|
190
|
+
custom: createCustomFields(
|
|
191
|
+
draft.custom,
|
|
192
|
+
context.projectKey,
|
|
193
|
+
this._storage
|
|
194
|
+
),
|
|
159
195
|
discountedPricePerQuantity: [],
|
|
160
196
|
lineItemMode: 'Standard',
|
|
161
197
|
name: draft.name,
|
|
@@ -178,12 +214,16 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
178
214
|
}
|
|
179
215
|
|
|
180
216
|
private customLineItemFromImportDraft(
|
|
181
|
-
|
|
217
|
+
context: RepositoryContext,
|
|
182
218
|
draft: CustomLineItemDraft
|
|
183
219
|
): CustomLineItem {
|
|
184
220
|
const lineItem: CustomLineItem = {
|
|
185
221
|
...getBaseResourceProperties(),
|
|
186
|
-
custom: createCustomFields(
|
|
222
|
+
custom: createCustomFields(
|
|
223
|
+
draft.custom,
|
|
224
|
+
context.projectKey,
|
|
225
|
+
this._storage
|
|
226
|
+
),
|
|
187
227
|
discountedPricePerQuantity: [],
|
|
188
228
|
money: createTypedMoney(draft.money),
|
|
189
229
|
name: draft.name,
|
|
@@ -197,11 +237,11 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
197
237
|
}
|
|
198
238
|
|
|
199
239
|
getWithOrderNumber(
|
|
200
|
-
|
|
240
|
+
context: RepositoryContext,
|
|
201
241
|
orderNumber: string,
|
|
202
242
|
params: QueryParams = {}
|
|
203
243
|
): Order | undefined {
|
|
204
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
244
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
205
245
|
...params,
|
|
206
246
|
where: [`orderNumber="${orderNumber}"`],
|
|
207
247
|
})
|
|
@@ -219,12 +259,12 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
219
259
|
|
|
220
260
|
actions = {
|
|
221
261
|
addPayment: (
|
|
222
|
-
|
|
262
|
+
context: RepositoryContext,
|
|
223
263
|
resource: Writable<Order>,
|
|
224
264
|
{ payment }: OrderAddPaymentAction
|
|
225
265
|
) => {
|
|
226
266
|
const resolvedPayment = this._storage.getByResourceIdentifier(
|
|
227
|
-
projectKey,
|
|
267
|
+
context.projectKey,
|
|
228
268
|
payment
|
|
229
269
|
)
|
|
230
270
|
if (!resolvedPayment) {
|
|
@@ -243,26 +283,26 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
243
283
|
})
|
|
244
284
|
},
|
|
245
285
|
changeOrderState: (
|
|
246
|
-
|
|
286
|
+
context: RepositoryContext,
|
|
247
287
|
resource: Writable<Order>,
|
|
248
288
|
{ orderState }: OrderChangeOrderStateAction
|
|
249
289
|
) => {
|
|
250
290
|
resource.orderState = orderState
|
|
251
291
|
},
|
|
252
292
|
changePaymentState: (
|
|
253
|
-
|
|
293
|
+
context: RepositoryContext,
|
|
254
294
|
resource: Writable<Order>,
|
|
255
295
|
{ paymentState }: OrderChangePaymentStateAction
|
|
256
296
|
) => {
|
|
257
297
|
resource.paymentState = paymentState
|
|
258
298
|
},
|
|
259
299
|
transitionState: (
|
|
260
|
-
|
|
300
|
+
context: RepositoryContext,
|
|
261
301
|
resource: Writable<Order>,
|
|
262
302
|
{ state }: OrderTransitionStateAction
|
|
263
303
|
) => {
|
|
264
304
|
const resolvedType = this._storage.getByResourceIdentifier(
|
|
265
|
-
projectKey,
|
|
305
|
+
context.projectKey,
|
|
266
306
|
state
|
|
267
307
|
) as State | null
|
|
268
308
|
|
|
@@ -275,21 +315,21 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
275
315
|
resource.state = { typeId: 'state', id: resolvedType.id }
|
|
276
316
|
},
|
|
277
317
|
setBillingAddress: (
|
|
278
|
-
|
|
318
|
+
context: RepositoryContext,
|
|
279
319
|
resource: Writable<Order>,
|
|
280
320
|
{ address }: OrderSetBillingAddressAction
|
|
281
321
|
) => {
|
|
282
322
|
resource.billingAddress = address
|
|
283
323
|
},
|
|
284
324
|
setCustomerEmail: (
|
|
285
|
-
|
|
325
|
+
context: RepositoryContext,
|
|
286
326
|
resource: Writable<Order>,
|
|
287
327
|
{ email }: OrderSetCustomerEmailAction
|
|
288
328
|
) => {
|
|
289
329
|
resource.customerEmail = email
|
|
290
330
|
},
|
|
291
331
|
setCustomField: (
|
|
292
|
-
|
|
332
|
+
context: RepositoryContext,
|
|
293
333
|
resource: Order,
|
|
294
334
|
{ name, value }: OrderSetCustomFieldAction
|
|
295
335
|
) => {
|
|
@@ -299,7 +339,7 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
299
339
|
resource.custom.fields[name] = value
|
|
300
340
|
},
|
|
301
341
|
setCustomType: (
|
|
302
|
-
|
|
342
|
+
context: RepositoryContext,
|
|
303
343
|
resource: Writable<Order>,
|
|
304
344
|
{ type, fields }: OrderSetCustomTypeAction
|
|
305
345
|
) => {
|
|
@@ -307,7 +347,7 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
307
347
|
resource.custom = undefined
|
|
308
348
|
} else {
|
|
309
349
|
const resolvedType = this._storage.getByResourceIdentifier(
|
|
310
|
-
projectKey,
|
|
350
|
+
context.projectKey,
|
|
311
351
|
type
|
|
312
352
|
)
|
|
313
353
|
if (!resolvedType) {
|
|
@@ -324,34 +364,34 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
324
364
|
}
|
|
325
365
|
},
|
|
326
366
|
setLocale: (
|
|
327
|
-
|
|
367
|
+
context: RepositoryContext,
|
|
328
368
|
resource: Writable<Order>,
|
|
329
369
|
{ locale }: OrderSetLocaleAction
|
|
330
370
|
) => {
|
|
331
371
|
resource.locale = locale
|
|
332
372
|
},
|
|
333
373
|
setOrderNumber: (
|
|
334
|
-
|
|
374
|
+
context: RepositoryContext,
|
|
335
375
|
resource: Writable<Order>,
|
|
336
376
|
{ orderNumber }: OrderSetOrderNumberAction
|
|
337
377
|
) => {
|
|
338
378
|
resource.orderNumber = orderNumber
|
|
339
379
|
},
|
|
340
380
|
setShippingAddress: (
|
|
341
|
-
|
|
381
|
+
context: RepositoryContext,
|
|
342
382
|
resource: Writable<Order>,
|
|
343
383
|
{ address }: OrderSetShippingAddressAction
|
|
344
384
|
) => {
|
|
345
385
|
resource.shippingAddress = address
|
|
346
386
|
},
|
|
347
387
|
setStore: (
|
|
348
|
-
|
|
388
|
+
context: RepositoryContext,
|
|
349
389
|
resource: Writable<Order>,
|
|
350
390
|
{ store }: OrderSetStoreAction
|
|
351
391
|
) => {
|
|
352
392
|
if (!store) return
|
|
353
393
|
const resolvedType = this._storage.getByResourceIdentifier(
|
|
354
|
-
projectKey,
|
|
394
|
+
context.projectKey,
|
|
355
395
|
store
|
|
356
396
|
)
|
|
357
397
|
if (!resolvedType) {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
Transaction,
|
|
13
13
|
TransactionDraft,
|
|
14
14
|
} from '@commercetools/platform-sdk'
|
|
15
|
-
import { AbstractResourceRepository } from './abstract'
|
|
15
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
16
16
|
import {
|
|
17
17
|
createCustomFields,
|
|
18
18
|
createTypedMoney,
|
|
@@ -27,7 +27,7 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
27
27
|
return 'payment'
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
create(
|
|
30
|
+
create(context: RepositoryContext, draft: PaymentDraft): Payment {
|
|
31
31
|
const resource: Payment = {
|
|
32
32
|
...getBaseResourceProperties(),
|
|
33
33
|
amountPlanned: createTypedMoney(draft.amountPlanned),
|
|
@@ -38,39 +38,43 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
38
38
|
state: draft.paymentStatus.state
|
|
39
39
|
? getReferenceFromResourceIdentifier<StateReference>(
|
|
40
40
|
draft.paymentStatus.state,
|
|
41
|
-
projectKey,
|
|
41
|
+
context.projectKey,
|
|
42
42
|
this._storage
|
|
43
43
|
)
|
|
44
44
|
: undefined,
|
|
45
45
|
}
|
|
46
46
|
: {},
|
|
47
47
|
transactions: (draft.transactions || []).map(t =>
|
|
48
|
-
this.transactionFromTransactionDraft(t,
|
|
48
|
+
this.transactionFromTransactionDraft(t, context)
|
|
49
49
|
),
|
|
50
50
|
interfaceInteractions: (draft.interfaceInteractions || []).map(
|
|
51
51
|
interaction =>
|
|
52
|
-
createCustomFields(interaction, projectKey, this._storage)!
|
|
52
|
+
createCustomFields(interaction, context.projectKey, this._storage)!
|
|
53
|
+
),
|
|
54
|
+
custom: createCustomFields(
|
|
55
|
+
draft.custom,
|
|
56
|
+
context.projectKey,
|
|
57
|
+
this._storage
|
|
53
58
|
),
|
|
54
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
this.save(
|
|
61
|
+
this.save(context, resource)
|
|
58
62
|
return resource
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
transactionFromTransactionDraft = (
|
|
62
66
|
draft: TransactionDraft,
|
|
63
|
-
|
|
67
|
+
context: RepositoryContext
|
|
64
68
|
) => ({
|
|
65
69
|
...draft,
|
|
66
70
|
id: uuidv4(),
|
|
67
71
|
amount: createTypedMoney(draft.amount),
|
|
68
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
72
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
69
73
|
})
|
|
70
74
|
|
|
71
75
|
actions = {
|
|
72
76
|
setCustomField: (
|
|
73
|
-
|
|
77
|
+
context: RepositoryContext,
|
|
74
78
|
resource: Payment,
|
|
75
79
|
{ name, value }: PaymentSetCustomFieldAction
|
|
76
80
|
) => {
|
|
@@ -81,7 +85,7 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
81
85
|
resource.custom.fields[name] = value
|
|
82
86
|
},
|
|
83
87
|
setCustomType: (
|
|
84
|
-
|
|
88
|
+
context: RepositoryContext,
|
|
85
89
|
resource: Writable<Payment>,
|
|
86
90
|
{ type, fields }: PaymentSetCustomTypeAction
|
|
87
91
|
) => {
|
|
@@ -89,7 +93,7 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
89
93
|
resource.custom = undefined
|
|
90
94
|
} else {
|
|
91
95
|
const resolvedType = this._storage.getByResourceIdentifier(
|
|
92
|
-
projectKey,
|
|
96
|
+
context.projectKey,
|
|
93
97
|
type
|
|
94
98
|
)
|
|
95
99
|
if (!resolvedType) {
|
|
@@ -106,17 +110,17 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
106
110
|
}
|
|
107
111
|
},
|
|
108
112
|
addTransaction: (
|
|
109
|
-
|
|
113
|
+
context: RepositoryContext,
|
|
110
114
|
resource: Writable<Payment>,
|
|
111
115
|
{ transaction }: PaymentAddTransactionAction
|
|
112
116
|
) => {
|
|
113
117
|
resource.transactions = [
|
|
114
118
|
...resource.transactions,
|
|
115
|
-
this.transactionFromTransactionDraft(transaction,
|
|
119
|
+
this.transactionFromTransactionDraft(transaction, context),
|
|
116
120
|
]
|
|
117
121
|
},
|
|
118
122
|
changeTransactionState: (
|
|
119
|
-
|
|
123
|
+
_context: RepositoryContext,
|
|
120
124
|
resource: Writable<Payment>,
|
|
121
125
|
{ transactionId, state }: PaymentChangeTransactionStateAction
|
|
122
126
|
) => {
|
|
@@ -130,12 +134,12 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
130
134
|
resource.transactions[index] = updatedTransaction
|
|
131
135
|
},
|
|
132
136
|
transitionState: (
|
|
133
|
-
|
|
137
|
+
context: RepositoryContext,
|
|
134
138
|
resource: Writable<Payment>,
|
|
135
139
|
{ state }: PaymentTransitionStateAction
|
|
136
140
|
) => {
|
|
137
141
|
const stateObj = this._storage.getByResourceIdentifier(
|
|
138
|
-
projectKey,
|
|
142
|
+
context.projectKey,
|
|
139
143
|
state
|
|
140
144
|
) as State | null
|
|
141
145
|
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ProductVariantDraft,
|
|
7
7
|
} from '@commercetools/platform-sdk'
|
|
8
8
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
|
-
import { AbstractResourceRepository } from './abstract'
|
|
9
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
10
|
import { RepositoryTypes } from '../types'
|
|
11
11
|
import { parseFilterExpression } from '../lib/filterParser'
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
15
15
|
return 'product-projection'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
create(
|
|
18
|
+
create(context: RepositoryContext, draft: ProductDraft): ProductProjection {
|
|
19
19
|
if (!draft.masterVariant) {
|
|
20
20
|
throw new Error(
|
|
21
21
|
`must provider mastervariant for product projection with key ${draft.key}`
|
|
@@ -44,16 +44,16 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
44
44
|
searchKeywords: draft.searchKeywords,
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
this.save(
|
|
47
|
+
this.save(context, resource)
|
|
48
48
|
|
|
49
49
|
return resource
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
search(
|
|
52
|
+
search(context: RepositoryContext, query: ParsedQs) {
|
|
53
53
|
const filter = (query['filter.query'] ?? query.filter) as any
|
|
54
54
|
const wherePredicate = filter ? parseFilterExpression(filter) : undefined
|
|
55
55
|
|
|
56
|
-
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
56
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
57
57
|
where: wherePredicate,
|
|
58
58
|
offset: query.offset ? Number(query.offset) : undefined,
|
|
59
59
|
limit: query.limit ? Number(query.limit) : undefined,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ProductTypeUpdateAction,
|
|
11
11
|
ReferenceTypeId,
|
|
12
12
|
} from '@commercetools/platform-sdk'
|
|
13
|
-
import { AbstractResourceRepository } from './abstract'
|
|
13
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
14
|
import { Writable } from 'types'
|
|
15
15
|
|
|
16
16
|
export class ProductTypeRepository extends AbstractResourceRepository {
|
|
@@ -18,23 +18,23 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
18
18
|
return 'product-type'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
create(
|
|
21
|
+
create(context: RepositoryContext, draft: ProductTypeDraft): ProductType {
|
|
22
22
|
const resource: ProductType = {
|
|
23
23
|
...getBaseResourceProperties(),
|
|
24
24
|
key: draft.key,
|
|
25
25
|
name: draft.name,
|
|
26
26
|
description: draft.description,
|
|
27
27
|
attributes: (draft.attributes ?? []).map(a =>
|
|
28
|
-
this.attributeDefinitionFromAttributeDefinitionDraft(
|
|
28
|
+
this.attributeDefinitionFromAttributeDefinitionDraft(context, a)
|
|
29
29
|
),
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
this.save(
|
|
32
|
+
this.save(context, resource)
|
|
33
33
|
return resource
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
attributeDefinitionFromAttributeDefinitionDraft = (
|
|
37
|
-
|
|
37
|
+
_context: RepositoryContext,
|
|
38
38
|
draft: AttributeDefinitionDraft
|
|
39
39
|
): AttributeDefinition => ({
|
|
40
40
|
...draft,
|
|
@@ -43,8 +43,8 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
43
43
|
isSearchable: draft.isSearchable ?? true,
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
getWithKey(
|
|
47
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
46
|
+
getWithKey(context: RepositoryContext, key: string): ProductType | undefined {
|
|
47
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
48
48
|
where: [`key="${key}"`],
|
|
49
49
|
})
|
|
50
50
|
if (result.count === 1) {
|
|
@@ -62,11 +62,15 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
62
62
|
actions: Partial<
|
|
63
63
|
Record<
|
|
64
64
|
ProductTypeUpdateAction['action'],
|
|
65
|
-
(
|
|
65
|
+
(
|
|
66
|
+
context: RepositoryContext,
|
|
67
|
+
resource: Writable<ProductType>,
|
|
68
|
+
action: any
|
|
69
|
+
) => void
|
|
66
70
|
>
|
|
67
71
|
> = {
|
|
68
72
|
changeLocalizedEnumValueLabel: (
|
|
69
|
-
|
|
73
|
+
context: RepositoryContext,
|
|
70
74
|
resource: Writable<ProductType>,
|
|
71
75
|
{
|
|
72
76
|
attributeName,
|
|
@@ -95,7 +99,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
95
99
|
})
|
|
96
100
|
},
|
|
97
101
|
changeLabel: (
|
|
98
|
-
|
|
102
|
+
context: RepositoryContext,
|
|
99
103
|
resource: Writable<ProductType>,
|
|
100
104
|
{ attributeName, label }: ProductTypeChangeLabelAction
|
|
101
105
|
) => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ReferenceTypeId,
|
|
11
11
|
} from '@commercetools/platform-sdk'
|
|
12
12
|
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
-
import { AbstractResourceRepository } from './abstract'
|
|
13
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
14
|
import { Writable } from '../types'
|
|
15
15
|
|
|
16
16
|
export class ProductRepository extends AbstractResourceRepository {
|
|
@@ -18,7 +18,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
18
18
|
return 'product'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
create(
|
|
21
|
+
create(context: RepositoryContext, draft: ProductDraft): Product {
|
|
22
22
|
const productData = {
|
|
23
23
|
name: draft.name,
|
|
24
24
|
slug: draft.slug,
|
|
@@ -47,14 +47,14 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
47
47
|
},
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
this.save(
|
|
50
|
+
this.save(context, resource)
|
|
51
51
|
|
|
52
52
|
return resource
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
actions = {
|
|
56
56
|
publish: (
|
|
57
|
-
|
|
57
|
+
context: RepositoryContext,
|
|
58
58
|
resource: Writable<Product>,
|
|
59
59
|
{ scope }: ProductPublishAction
|
|
60
60
|
) => {
|
|
@@ -67,7 +67,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
67
67
|
resource.masterData.published = true
|
|
68
68
|
},
|
|
69
69
|
setAttribute: (
|
|
70
|
-
|
|
70
|
+
context: RepositoryContext,
|
|
71
71
|
resource: Writable<Product>,
|
|
72
72
|
{ variantId, sku, name, value, staged }: ProductSetAttributeAction
|
|
73
73
|
) => {
|