@labdigital/commercetools-mock 2.53.2 → 2.55.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.d.ts +107 -77
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +330 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/lib/productSearchFilter.test.ts +1 -0
- package/src/lib/projectionSearchFilter.test.ts +1 -0
- package/src/priceSelector.test.ts +1 -0
- package/src/product-projection-search.ts +2 -0
- package/src/product-search.ts +1 -0
- package/src/repositories/business-unit.ts +157 -2
- package/src/repositories/cart/index.test.ts +2 -0
- package/src/repositories/cart/index.ts +1 -0
- package/src/repositories/cart-discount/index.ts +1 -1
- package/src/repositories/customer/index.ts +2 -0
- package/src/repositories/discount-group/actions.ts +50 -0
- package/src/repositories/discount-group/index.ts +29 -0
- package/src/repositories/index.ts +6 -0
- package/src/repositories/order/index.test.ts +126 -125
- package/src/repositories/payment/actions.ts +87 -0
- package/src/repositories/payment/index.ts +1 -1
- package/src/repositories/product/index.ts +1 -0
- package/src/repositories/product-type.ts +1 -0
- package/src/repositories/quote/index.ts +1 -0
- package/src/repositories/quote-request/index.test.ts +1 -0
- package/src/repositories/quote-request/index.ts +1 -0
- package/src/repositories/recurrence-policy/actions.ts +53 -0
- package/src/repositories/recurrence-policy/index.ts +36 -0
- package/src/repositories/recurring-order/actions.ts +157 -0
- package/src/repositories/recurring-order/index.ts +52 -0
- package/src/repositories/review.test.ts +2 -0
- package/src/repositories/shopping-list/actions.ts +1 -0
- package/src/repositories/shopping-list/index.ts +1 -0
- package/src/services/business-units.test.ts +586 -15
- package/src/services/discount-group.test.ts +270 -0
- package/src/services/discount-group.ts +16 -0
- package/src/services/index.ts +12 -0
- package/src/services/my-cart.test.ts +1 -0
- package/src/services/my-payment.test.ts +1 -0
- package/src/services/payment.test.ts +1 -0
- package/src/services/product-projection.test.ts +4 -0
- package/src/services/product-type.test.ts +1 -0
- package/src/services/product.test.ts +1 -0
- package/src/services/recurrence-policy.test.ts +316 -0
- package/src/services/recurrence-policy.ts +16 -0
- package/src/services/recurring-order.test.ts +424 -0
- package/src/services/recurring-order.ts +16 -0
- package/src/services/shopping-list.test.ts +3 -0
- package/src/storage/in-memory.ts +6 -0
- package/src/testing/business-unit.ts +48 -0
- package/src/testing/type.ts +20 -0
- package/src/types.ts +6 -0
|
@@ -35,6 +35,7 @@ describe("Order repository", () => {
|
|
|
35
35
|
} as unknown as LineItem,
|
|
36
36
|
],
|
|
37
37
|
customLineItems: [],
|
|
38
|
+
priceRoundingMode: "HalfEven",
|
|
38
39
|
totalPrice: {
|
|
39
40
|
type: "centPrecision",
|
|
40
41
|
currencyCode: "EUR",
|
|
@@ -293,132 +294,132 @@ describe("Order repository", () => {
|
|
|
293
294
|
});
|
|
294
295
|
/*
|
|
295
296
|
test('import non exiting product', async () => {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
297
|
+
const draft: OrderImportDraft = {
|
|
298
|
+
orderNumber: '100000001',
|
|
299
|
+
totalPrice: {
|
|
300
|
+
centAmount: 1000,
|
|
301
|
+
currencyCode: 'EUR',
|
|
302
|
+
},
|
|
303
|
+
customLineItems: [],
|
|
304
|
+
lineItems: [
|
|
305
|
+
{
|
|
306
|
+
id: '15fc56ba-a74e-4cf8-b4b0-bada5c101541',
|
|
307
|
+
productId: 'PRODUCTID',
|
|
308
|
+
name: {
|
|
309
|
+
'en-US': 'The product',
|
|
310
|
+
},
|
|
311
|
+
productType: {
|
|
312
|
+
typeId: 'product-type',
|
|
313
|
+
id: '109caecb-abe6-4900-ab03-7af5af985ff3',
|
|
314
|
+
// @ts-ignore
|
|
315
|
+
version: 1,
|
|
316
|
+
},
|
|
317
|
+
variant: {
|
|
318
|
+
id: 1,
|
|
319
|
+
sku: 'MYSKU',
|
|
320
|
+
key: 'MYKEY',
|
|
321
|
+
prices: [
|
|
322
|
+
{
|
|
323
|
+
value: {
|
|
324
|
+
// @ts-ignore
|
|
325
|
+
type: 'centPrecision',
|
|
326
|
+
currencyCode: 'EUR',
|
|
327
|
+
centAmount: 14900,
|
|
328
|
+
fractionDigits: 2,
|
|
329
|
+
},
|
|
330
|
+
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
331
|
+
country: 'NL',
|
|
332
|
+
// channel: {
|
|
333
|
+
// typeId: 'channel',
|
|
334
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
335
|
+
// },
|
|
336
|
+
// custom: {
|
|
337
|
+
// type: {
|
|
338
|
+
// typeId: 'type',
|
|
339
|
+
// id: '55071385-b6e4-44c4-8c4b-6f2ec0f23649',
|
|
340
|
+
// },
|
|
341
|
+
// fields: {},
|
|
342
|
+
// },
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
images: [],
|
|
346
|
+
attributes: [],
|
|
347
|
+
assets: [],
|
|
348
|
+
},
|
|
349
|
+
price: {
|
|
350
|
+
value: {
|
|
351
|
+
// @ts-ignore
|
|
352
|
+
type: 'centPrecision',
|
|
353
|
+
currencyCode: 'EUR',
|
|
354
|
+
centAmount: 14900,
|
|
355
|
+
fractionDigits: 2,
|
|
356
|
+
},
|
|
357
|
+
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
358
|
+
country: 'NL',
|
|
359
|
+
// channel: {
|
|
360
|
+
// typeId: 'channel',
|
|
361
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
362
|
+
// },
|
|
363
|
+
// custom: {
|
|
364
|
+
// type: {
|
|
365
|
+
// typeId: 'type',
|
|
366
|
+
// id: '55071385-b6e4-44c4-8c4b-6f2ec0f23649',
|
|
367
|
+
// },
|
|
368
|
+
// fields: {},
|
|
369
|
+
// },
|
|
370
|
+
},
|
|
371
|
+
quantity: 3,
|
|
372
|
+
discountedPricePerQuantity: [],
|
|
373
|
+
// distributionChannel: {
|
|
374
|
+
// typeId: 'channel',
|
|
375
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
376
|
+
// },
|
|
377
|
+
taxRate: {
|
|
378
|
+
name: '21% BTW',
|
|
379
|
+
amount: 0.21,
|
|
380
|
+
includedInPrice: true,
|
|
381
|
+
country: 'NL',
|
|
382
|
+
id: 'Z0wLUuYw',
|
|
383
|
+
subRates: [],
|
|
384
|
+
},
|
|
385
|
+
addedAt: '2020-12-08T09:10:27.085Z',
|
|
386
|
+
lastModifiedAt: '2020-12-08T09:10:27.085Z',
|
|
387
|
+
// state: [
|
|
388
|
+
// {
|
|
389
|
+
// quantity: 3,
|
|
390
|
+
// state: {
|
|
391
|
+
// typeId: 'state',
|
|
392
|
+
// id: 'f1d9531d-41f0-46a7-82f2-c4b0748aa9f5',
|
|
393
|
+
// },
|
|
394
|
+
// },
|
|
395
|
+
// ],
|
|
396
|
+
priceMode: 'Platform',
|
|
397
|
+
totalPrice: {
|
|
398
|
+
type: 'centPrecision',
|
|
399
|
+
currencyCode: 'EUR',
|
|
400
|
+
centAmount: 44700,
|
|
401
|
+
fractionDigits: 2,
|
|
402
|
+
},
|
|
403
|
+
taxedPrice: {
|
|
404
|
+
totalNet: {
|
|
405
|
+
type: 'centPrecision',
|
|
406
|
+
currencyCode: 'EUR',
|
|
407
|
+
centAmount: 36942,
|
|
408
|
+
fractionDigits: 2,
|
|
409
|
+
},
|
|
410
|
+
totalGross: {
|
|
411
|
+
type: 'centPrecision',
|
|
412
|
+
currencyCode: 'EUR',
|
|
413
|
+
centAmount: 44700,
|
|
414
|
+
fractionDigits: 2,
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
lineItemMode: 'Standard',
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
}
|
|
420
421
|
|
|
421
|
-
|
|
422
|
+
repository.import('dummy', draft)
|
|
422
423
|
})
|
|
423
424
|
*/
|
|
424
425
|
});
|
|
@@ -13,9 +13,14 @@ import type {
|
|
|
13
13
|
PaymentSetCustomerAction,
|
|
14
14
|
PaymentSetInterfaceIdAction,
|
|
15
15
|
PaymentSetKeyAction,
|
|
16
|
+
PaymentSetMethodInfoAction,
|
|
17
|
+
PaymentSetMethodInfoCustomFieldAction,
|
|
18
|
+
PaymentSetMethodInfoCustomTypeAction,
|
|
19
|
+
PaymentSetMethodInfoInterfaceAccountAction,
|
|
16
20
|
PaymentSetMethodInfoInterfaceAction,
|
|
17
21
|
PaymentSetMethodInfoMethodAction,
|
|
18
22
|
PaymentSetMethodInfoNameAction,
|
|
23
|
+
PaymentSetMethodInfoTokenAction,
|
|
19
24
|
PaymentSetStatusInterfaceCodeAction,
|
|
20
25
|
PaymentSetStatusInterfaceTextAction,
|
|
21
26
|
PaymentSetTransactionCustomFieldAction,
|
|
@@ -299,4 +304,86 @@ export class PaymentUpdateHandler
|
|
|
299
304
|
obj: stateObj,
|
|
300
305
|
};
|
|
301
306
|
}
|
|
307
|
+
|
|
308
|
+
setMethodInfo(
|
|
309
|
+
context: RepositoryContext,
|
|
310
|
+
resource: Writable<Payment>,
|
|
311
|
+
{
|
|
312
|
+
paymentInterface,
|
|
313
|
+
method,
|
|
314
|
+
name,
|
|
315
|
+
interfaceAccount,
|
|
316
|
+
token,
|
|
317
|
+
}: PaymentSetMethodInfoAction,
|
|
318
|
+
) {
|
|
319
|
+
if (paymentInterface !== undefined) {
|
|
320
|
+
resource.paymentMethodInfo.paymentInterface = paymentInterface;
|
|
321
|
+
}
|
|
322
|
+
if (method !== undefined) {
|
|
323
|
+
resource.paymentMethodInfo.method = method;
|
|
324
|
+
}
|
|
325
|
+
if (name !== undefined) {
|
|
326
|
+
resource.paymentMethodInfo.name = name;
|
|
327
|
+
}
|
|
328
|
+
if (interfaceAccount !== undefined) {
|
|
329
|
+
resource.paymentMethodInfo.interfaceAccount = interfaceAccount;
|
|
330
|
+
}
|
|
331
|
+
if (token !== undefined) {
|
|
332
|
+
resource.paymentMethodInfo.token = token;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
setMethodInfoCustomField(
|
|
337
|
+
context: RepositoryContext,
|
|
338
|
+
resource: Writable<Payment>,
|
|
339
|
+
{ name, value }: PaymentSetMethodInfoCustomFieldAction,
|
|
340
|
+
) {
|
|
341
|
+
if (!resource.paymentMethodInfo.custom) {
|
|
342
|
+
throw new Error("PaymentMethodInfo has no custom field");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
resource.paymentMethodInfo.custom.fields[name] = value;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
setMethodInfoCustomType(
|
|
349
|
+
context: RepositoryContext,
|
|
350
|
+
resource: Writable<Payment>,
|
|
351
|
+
{ type, fields }: PaymentSetMethodInfoCustomTypeAction,
|
|
352
|
+
) {
|
|
353
|
+
if (!type) {
|
|
354
|
+
resource.paymentMethodInfo.custom = undefined;
|
|
355
|
+
} else {
|
|
356
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
357
|
+
context.projectKey,
|
|
358
|
+
type,
|
|
359
|
+
);
|
|
360
|
+
if (!resolvedType) {
|
|
361
|
+
throw new Error(`Type ${type} not found`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
resource.paymentMethodInfo.custom = {
|
|
365
|
+
type: {
|
|
366
|
+
typeId: "type",
|
|
367
|
+
id: resolvedType.id,
|
|
368
|
+
},
|
|
369
|
+
fields: fields ?? {},
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
setMethodInfoInterfaceAccount(
|
|
375
|
+
_context: RepositoryContext,
|
|
376
|
+
resource: Writable<Payment>,
|
|
377
|
+
{ interfaceAccount }: PaymentSetMethodInfoInterfaceAccountAction,
|
|
378
|
+
) {
|
|
379
|
+
resource.paymentMethodInfo.interfaceAccount = interfaceAccount;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
setMethodInfoToken(
|
|
383
|
+
_context: RepositoryContext,
|
|
384
|
+
resource: Writable<Payment>,
|
|
385
|
+
{ token }: PaymentSetMethodInfoTokenAction,
|
|
386
|
+
) {
|
|
387
|
+
resource.paymentMethodInfo.token = token;
|
|
388
|
+
}
|
|
302
389
|
}
|
|
@@ -26,7 +26,7 @@ export class PaymentRepository extends AbstractResourceRepository<"payment"> {
|
|
|
26
26
|
...getBaseResourceProperties(),
|
|
27
27
|
key: draft.key,
|
|
28
28
|
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
29
|
-
paymentMethodInfo: draft.paymentMethodInfo!,
|
|
29
|
+
paymentMethodInfo: { ...draft.paymentMethodInfo!, custom: undefined },
|
|
30
30
|
paymentStatus: draft.paymentStatus
|
|
31
31
|
? {
|
|
32
32
|
...draft.paymentStatus,
|
|
@@ -108,6 +108,7 @@ export class ProductRepository extends AbstractResourceRepository<"product"> {
|
|
|
108
108
|
name: draft.name,
|
|
109
109
|
slug: draft.slug,
|
|
110
110
|
description: draft.description,
|
|
111
|
+
attributes: draft.attributes ?? [],
|
|
111
112
|
categories: categoryReferences,
|
|
112
113
|
masterVariant: variantFromDraft(
|
|
113
114
|
context,
|
|
@@ -44,6 +44,7 @@ const attributeDefinitionFromAttributeDefinitionDraft = (
|
|
|
44
44
|
draft: AttributeDefinitionDraft,
|
|
45
45
|
): AttributeDefinition => ({
|
|
46
46
|
...draft,
|
|
47
|
+
level: draft.level ?? "Variant",
|
|
47
48
|
attributeConstraint: draft.attributeConstraint ?? "None",
|
|
48
49
|
inputHint: draft.inputHint ?? "SingleLine",
|
|
49
50
|
inputTip:
|
|
@@ -65,6 +65,7 @@ export class QuoteRequestRepository extends AbstractResourceRepository<"quote-re
|
|
|
65
65
|
directDiscounts: cart.directDiscounts,
|
|
66
66
|
lineItems: cart.lineItems,
|
|
67
67
|
paymentInfo: cart.paymentInfo,
|
|
68
|
+
priceRoundingMode: cart.priceRoundingMode,
|
|
68
69
|
quoteRequestState: "Submitted",
|
|
69
70
|
shippingAddress: cart.shippingAddress,
|
|
70
71
|
taxCalculationMode: cart.taxCalculationMode,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RecurrencePolicy,
|
|
3
|
+
RecurrencePolicySetDescriptionAction,
|
|
4
|
+
RecurrencePolicySetKeyAction,
|
|
5
|
+
RecurrencePolicySetNameAction,
|
|
6
|
+
RecurrencePolicySetScheduleAction,
|
|
7
|
+
RecurrencePolicyUpdateAction,
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import type { Writable } from "~src/types";
|
|
10
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
11
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
12
|
+
|
|
13
|
+
export class RecurrencePolicyUpdateHandler
|
|
14
|
+
extends AbstractUpdateHandler
|
|
15
|
+
implements
|
|
16
|
+
Partial<
|
|
17
|
+
UpdateHandlerInterface<RecurrencePolicy, RecurrencePolicyUpdateAction>
|
|
18
|
+
>
|
|
19
|
+
{
|
|
20
|
+
setKey(
|
|
21
|
+
context: RepositoryContext,
|
|
22
|
+
resource: Writable<RecurrencePolicy>,
|
|
23
|
+
{ key }: RecurrencePolicySetKeyAction,
|
|
24
|
+
) {
|
|
25
|
+
if (key) {
|
|
26
|
+
resource.key = key;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setDescription(
|
|
31
|
+
context: RepositoryContext,
|
|
32
|
+
resource: Writable<RecurrencePolicy>,
|
|
33
|
+
{ description }: RecurrencePolicySetDescriptionAction,
|
|
34
|
+
) {
|
|
35
|
+
resource.description = description;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setName(
|
|
39
|
+
context: RepositoryContext,
|
|
40
|
+
resource: Writable<RecurrencePolicy>,
|
|
41
|
+
{ name }: RecurrencePolicySetNameAction,
|
|
42
|
+
) {
|
|
43
|
+
resource.name = name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setSchedule(
|
|
47
|
+
context: RepositoryContext,
|
|
48
|
+
resource: Writable<RecurrencePolicy>,
|
|
49
|
+
{ schedule }: RecurrencePolicySetScheduleAction,
|
|
50
|
+
) {
|
|
51
|
+
resource.schedule = schedule;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import type {
|
|
3
|
+
RecurrencePolicy,
|
|
4
|
+
RecurrencePolicyDraft,
|
|
5
|
+
RecurringOrder,
|
|
6
|
+
RecurringOrderDraft,
|
|
7
|
+
} from "@commercetools/platform-sdk";
|
|
8
|
+
import type { Config } from "~src/config";
|
|
9
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
10
|
+
import {
|
|
11
|
+
AbstractResourceRepository,
|
|
12
|
+
type RepositoryContext,
|
|
13
|
+
} from "../abstract";
|
|
14
|
+
import { OrderRepository } from "../order";
|
|
15
|
+
import { RecurrencePolicyUpdateHandler } from "./actions";
|
|
16
|
+
|
|
17
|
+
export class RecurrencePolicyRepository extends AbstractResourceRepository<"recurrence-policy"> {
|
|
18
|
+
constructor(config: Config) {
|
|
19
|
+
super("recurrence-policy", config);
|
|
20
|
+
this.actions = new RecurrencePolicyUpdateHandler(config.storage);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
create(
|
|
24
|
+
context: RepositoryContext,
|
|
25
|
+
draft: RecurrencePolicyDraft,
|
|
26
|
+
): RecurrencePolicy {
|
|
27
|
+
const resource: RecurrencePolicy = {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
key: draft.key,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
description: draft.description,
|
|
32
|
+
schedule: draft.schedule,
|
|
33
|
+
};
|
|
34
|
+
return this.saveNew(context, resource);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RecurringOrder,
|
|
3
|
+
RecurringOrderSetCustomFieldAction,
|
|
4
|
+
RecurringOrderSetCustomTypeAction,
|
|
5
|
+
RecurringOrderSetExpiresAtAction,
|
|
6
|
+
RecurringOrderSetKeyAction,
|
|
7
|
+
RecurringOrderSetOrderSkipConfigurationAction,
|
|
8
|
+
RecurringOrderSetScheduleAction,
|
|
9
|
+
RecurringOrderSetStartsAtAction,
|
|
10
|
+
RecurringOrderSetStateAction,
|
|
11
|
+
RecurringOrderTransitionStateAction,
|
|
12
|
+
RecurringOrderUpdateAction,
|
|
13
|
+
} from "@commercetools/platform-sdk";
|
|
14
|
+
import type { Writable } from "~src/types";
|
|
15
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
16
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
17
|
+
|
|
18
|
+
export class RecurringOrderUpdateHandler
|
|
19
|
+
extends AbstractUpdateHandler
|
|
20
|
+
implements
|
|
21
|
+
Partial<UpdateHandlerInterface<RecurringOrder, RecurringOrderUpdateAction>>
|
|
22
|
+
{
|
|
23
|
+
setCustomField(
|
|
24
|
+
context: RepositoryContext,
|
|
25
|
+
resource: Writable<RecurringOrder>,
|
|
26
|
+
{ name, value }: RecurringOrderSetCustomFieldAction,
|
|
27
|
+
) {
|
|
28
|
+
if (!resource.custom) {
|
|
29
|
+
throw new Error("Resource has no custom field");
|
|
30
|
+
}
|
|
31
|
+
if (value === null) {
|
|
32
|
+
delete resource.custom.fields[name];
|
|
33
|
+
} else {
|
|
34
|
+
resource.custom.fields[name] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setCustomType(
|
|
39
|
+
context: RepositoryContext,
|
|
40
|
+
resource: Writable<RecurringOrder>,
|
|
41
|
+
{ type, fields }: RecurringOrderSetCustomTypeAction,
|
|
42
|
+
) {
|
|
43
|
+
if (!type) {
|
|
44
|
+
resource.custom = undefined;
|
|
45
|
+
} else {
|
|
46
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
47
|
+
context.projectKey,
|
|
48
|
+
type,
|
|
49
|
+
);
|
|
50
|
+
if (!resolvedType) {
|
|
51
|
+
throw new Error(`Type ${type} not found`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
resource.custom = {
|
|
55
|
+
type: {
|
|
56
|
+
typeId: "type",
|
|
57
|
+
id: resolvedType.id,
|
|
58
|
+
},
|
|
59
|
+
fields: fields || {},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setExpiresAt(
|
|
65
|
+
context: RepositoryContext,
|
|
66
|
+
resource: Writable<RecurringOrder>,
|
|
67
|
+
{ expiresAt }: RecurringOrderSetExpiresAtAction,
|
|
68
|
+
) {
|
|
69
|
+
resource.expiresAt = expiresAt;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setKey(
|
|
73
|
+
context: RepositoryContext,
|
|
74
|
+
resource: Writable<RecurringOrder>,
|
|
75
|
+
{ key }: RecurringOrderSetKeyAction,
|
|
76
|
+
) {
|
|
77
|
+
resource.key = key;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setOrderSkipConfiguration(
|
|
81
|
+
context: RepositoryContext,
|
|
82
|
+
resource: Writable<RecurringOrder>,
|
|
83
|
+
{
|
|
84
|
+
skipConfiguration,
|
|
85
|
+
updatedExpiresAt,
|
|
86
|
+
}: RecurringOrderSetOrderSkipConfigurationAction,
|
|
87
|
+
) {
|
|
88
|
+
if (skipConfiguration) {
|
|
89
|
+
resource.skipConfiguration = {
|
|
90
|
+
type: skipConfiguration.type,
|
|
91
|
+
totalToSkip: skipConfiguration.totalToSkip,
|
|
92
|
+
skipped: 0,
|
|
93
|
+
lastSkippedAt: undefined,
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
resource.skipConfiguration = undefined;
|
|
97
|
+
}
|
|
98
|
+
if (updatedExpiresAt !== undefined) {
|
|
99
|
+
resource.expiresAt = updatedExpiresAt;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setSchedule(
|
|
104
|
+
context: RepositoryContext,
|
|
105
|
+
resource: Writable<RecurringOrder>,
|
|
106
|
+
{ recurrencePolicy }: RecurringOrderSetScheduleAction,
|
|
107
|
+
) {
|
|
108
|
+
resource.schedule = {
|
|
109
|
+
...resource.schedule,
|
|
110
|
+
...recurrencePolicy,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setStartsAt(
|
|
115
|
+
context: RepositoryContext,
|
|
116
|
+
resource: Writable<RecurringOrder>,
|
|
117
|
+
{ startsAt }: RecurringOrderSetStartsAtAction,
|
|
118
|
+
) {
|
|
119
|
+
resource.startsAt = startsAt;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setRecurringOrderState(
|
|
123
|
+
context: RepositoryContext,
|
|
124
|
+
resource: Writable<RecurringOrder>,
|
|
125
|
+
{ recurringOrderState }: RecurringOrderSetStateAction,
|
|
126
|
+
) {
|
|
127
|
+
// Map the state draft to the actual state
|
|
128
|
+
switch (recurringOrderState.type) {
|
|
129
|
+
case "active":
|
|
130
|
+
resource.recurringOrderState = "Active";
|
|
131
|
+
if (recurringOrderState.resumesAt) {
|
|
132
|
+
resource.resumesAt = recurringOrderState.resumesAt;
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case "canceled":
|
|
136
|
+
resource.recurringOrderState = "Canceled";
|
|
137
|
+
break;
|
|
138
|
+
case "expired":
|
|
139
|
+
resource.recurringOrderState = "Expired";
|
|
140
|
+
break;
|
|
141
|
+
case "paused":
|
|
142
|
+
resource.recurringOrderState = "Paused";
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
transitionState(
|
|
148
|
+
context: RepositoryContext,
|
|
149
|
+
resource: Writable<RecurringOrder>,
|
|
150
|
+
{ state, force }: RecurringOrderTransitionStateAction,
|
|
151
|
+
) {
|
|
152
|
+
resource.state = {
|
|
153
|
+
typeId: "state",
|
|
154
|
+
id: state.id!,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|