@labdigital/commercetools-mock 1.5.0 → 1.6.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.
Files changed (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +105 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +29 -7
  5. package/dist/index.d.ts +29 -7
  6. package/dist/index.js +105 -17
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -3
  9. package/src/constants.ts +2 -2
  10. package/src/ctMock.ts +176 -176
  11. package/src/exceptions.ts +10 -10
  12. package/src/helpers.ts +26 -26
  13. package/src/index.test.ts +173 -173
  14. package/src/index.ts +3 -3
  15. package/src/lib/expandParser.ts +19 -19
  16. package/src/lib/haversine.test.ts +13 -13
  17. package/src/lib/haversine.ts +14 -14
  18. package/src/lib/masking.ts +15 -15
  19. package/src/lib/parser.ts +2 -2
  20. package/src/lib/predicateParser.test.ts +204 -204
  21. package/src/lib/predicateParser.ts +398 -398
  22. package/src/lib/projectionSearchFilter.test.ts +168 -168
  23. package/src/lib/projectionSearchFilter.ts +272 -269
  24. package/src/lib/proxy.ts +8 -8
  25. package/src/oauth/errors.ts +4 -4
  26. package/src/oauth/helpers.ts +6 -6
  27. package/src/oauth/server.ts +103 -101
  28. package/src/oauth/store.ts +27 -27
  29. package/src/priceSelector.test.ts +68 -68
  30. package/src/priceSelector.ts +70 -70
  31. package/src/product-projection-search.ts +296 -296
  32. package/src/projectAPI.test.ts +3 -3
  33. package/src/projectAPI.ts +46 -46
  34. package/src/repositories/abstract.ts +190 -190
  35. package/src/repositories/associate-role.ts +10 -7
  36. package/src/repositories/attribute-group.ts +63 -8
  37. package/src/repositories/business-unit.ts +10 -7
  38. package/src/repositories/cart-discount.ts +134 -134
  39. package/src/repositories/cart.ts +517 -514
  40. package/src/repositories/category.ts +170 -167
  41. package/src/repositories/channel.ts +114 -111
  42. package/src/repositories/custom-object.ts +66 -63
  43. package/src/repositories/customer-group.ts +72 -69
  44. package/src/repositories/customer.ts +90 -90
  45. package/src/repositories/discount-code.ts +171 -168
  46. package/src/repositories/errors.ts +15 -15
  47. package/src/repositories/extension.ts +79 -76
  48. package/src/repositories/helpers.ts +180 -180
  49. package/src/repositories/index.ts +39 -39
  50. package/src/repositories/inventory-entry.ts +98 -95
  51. package/src/repositories/my-order.ts +11 -11
  52. package/src/repositories/order-edit.ts +29 -29
  53. package/src/repositories/order.test.ts +191 -191
  54. package/src/repositories/order.ts +393 -393
  55. package/src/repositories/payment.ts +155 -155
  56. package/src/repositories/product-discount.ts +149 -149
  57. package/src/repositories/product-projection.ts +116 -52
  58. package/src/repositories/product-selection.ts +31 -31
  59. package/src/repositories/product-type.ts +156 -156
  60. package/src/repositories/product.ts +600 -597
  61. package/src/repositories/project.ts +136 -135
  62. package/src/repositories/quote-request.ts +19 -19
  63. package/src/repositories/quote.ts +19 -19
  64. package/src/repositories/review.ts +24 -24
  65. package/src/repositories/shipping-method.ts +217 -217
  66. package/src/repositories/shopping-list.ts +49 -49
  67. package/src/repositories/staged-quote.ts +20 -20
  68. package/src/repositories/standalone-price.ts +72 -61
  69. package/src/repositories/state.ts +84 -84
  70. package/src/repositories/store.ts +114 -114
  71. package/src/repositories/subscription.ts +40 -40
  72. package/src/repositories/tax-category.ts +98 -98
  73. package/src/repositories/type.ts +157 -157
  74. package/src/repositories/zone.ts +71 -71
  75. package/src/server.ts +2 -2
  76. package/src/services/abstract.ts +173 -173
  77. package/src/services/attribute-group.ts +16 -0
  78. package/src/services/cart-discount.ts +8 -8
  79. package/src/services/cart.test.ts +409 -409
  80. package/src/services/cart.ts +50 -50
  81. package/src/services/category.test.ts +25 -25
  82. package/src/services/category.ts +8 -8
  83. package/src/services/channel.ts +8 -8
  84. package/src/services/custom-object.test.ts +184 -184
  85. package/src/services/custom-object.ts +48 -48
  86. package/src/services/customer-group.ts +8 -8
  87. package/src/services/customer.test.ts +151 -151
  88. package/src/services/customer.ts +27 -27
  89. package/src/services/discount-code.ts +8 -8
  90. package/src/services/extension.ts +8 -8
  91. package/src/services/index.ts +52 -44
  92. package/src/services/inventory-entry.test.ts +162 -162
  93. package/src/services/inventory-entry.ts +8 -8
  94. package/src/services/my-cart.test.ts +78 -78
  95. package/src/services/my-cart.ts +28 -28
  96. package/src/services/my-customer.test.ts +44 -44
  97. package/src/services/my-customer.ts +53 -53
  98. package/src/services/my-order.ts +20 -20
  99. package/src/services/my-payment.test.ts +65 -65
  100. package/src/services/my-payment.ts +8 -8
  101. package/src/services/order.test.ts +527 -527
  102. package/src/services/order.ts +31 -31
  103. package/src/services/payment.test.ts +65 -65
  104. package/src/services/payment.ts +8 -8
  105. package/src/services/product-discount.ts +8 -8
  106. package/src/services/product-projection.test.ts +492 -428
  107. package/src/services/product-projection.ts +32 -18
  108. package/src/services/product-type.test.ts +56 -56
  109. package/src/services/product-type.ts +8 -8
  110. package/src/services/product.test.ts +510 -510
  111. package/src/services/product.ts +8 -8
  112. package/src/services/project.ts +34 -34
  113. package/src/services/shipping-method.test.ts +81 -81
  114. package/src/services/shipping-method.ts +12 -12
  115. package/src/services/shopping-list.ts +8 -8
  116. package/src/services/standalone-price.test.ts +256 -256
  117. package/src/services/standalone-price.ts +8 -8
  118. package/src/services/state.test.ts +42 -42
  119. package/src/services/state.ts +8 -8
  120. package/src/services/store.test.ts +57 -57
  121. package/src/services/store.ts +8 -8
  122. package/src/services/subscription.ts +8 -8
  123. package/src/services/tax-category.test.ts +61 -61
  124. package/src/services/tax-category.ts +8 -8
  125. package/src/services/type.ts +8 -8
  126. package/src/services/zone.ts +8 -8
  127. package/src/storage/abstract.ts +58 -58
  128. package/src/storage/in-memory.ts +419 -419
  129. package/src/types.ts +82 -82
@@ -1,174 +1,174 @@
1
1
  import type {
2
- Payment,
3
- PaymentAddTransactionAction,
4
- PaymentChangeTransactionStateAction,
5
- PaymentDraft,
6
- PaymentSetCustomFieldAction,
7
- PaymentSetCustomTypeAction,
8
- PaymentTransitionStateAction,
9
- State,
10
- StateReference,
11
- Transaction,
12
- TransactionDraft,
2
+ Payment,
3
+ PaymentAddTransactionAction,
4
+ PaymentChangeTransactionStateAction,
5
+ PaymentDraft,
6
+ PaymentSetCustomFieldAction,
7
+ PaymentSetCustomTypeAction,
8
+ PaymentTransitionStateAction,
9
+ State,
10
+ StateReference,
11
+ Transaction,
12
+ TransactionDraft,
13
13
  } from '@commercetools/platform-sdk'
14
14
  import { v4 as uuidv4 } from 'uuid'
15
15
  import { getBaseResourceProperties } from '../helpers.js'
16
16
  import type { Writable } from '../types.js'
17
17
  import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
18
18
  import {
19
- createCentPrecisionMoney,
20
- createCustomFields,
21
- getReferenceFromResourceIdentifier,
19
+ createCentPrecisionMoney,
20
+ createCustomFields,
21
+ getReferenceFromResourceIdentifier,
22
22
  } from './helpers.js'
23
23
 
24
24
  export class PaymentRepository extends AbstractResourceRepository<'payment'> {
25
- getTypeId() {
26
- return 'payment' as const
27
- }
25
+ getTypeId() {
26
+ return 'payment' as const
27
+ }
28
28
 
29
- create(context: RepositoryContext, draft: PaymentDraft): Payment {
30
- const resource: Payment = {
31
- ...getBaseResourceProperties(),
32
- amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
33
- paymentMethodInfo: draft.paymentMethodInfo!,
34
- paymentStatus: draft.paymentStatus
35
- ? {
36
- ...draft.paymentStatus,
37
- state: draft.paymentStatus.state
38
- ? getReferenceFromResourceIdentifier<StateReference>(
39
- draft.paymentStatus.state,
40
- context.projectKey,
41
- this._storage
42
- )
43
- : undefined,
44
- }
45
- : {},
46
- transactions: (draft.transactions || []).map((t) =>
47
- this.transactionFromTransactionDraft(t, context)
48
- ),
49
- interfaceInteractions: (draft.interfaceInteractions || []).map(
50
- (interaction) =>
51
- createCustomFields(interaction, context.projectKey, this._storage)!
52
- ),
53
- custom: createCustomFields(
54
- draft.custom,
55
- context.projectKey,
56
- this._storage
57
- ),
58
- }
29
+ create(context: RepositoryContext, draft: PaymentDraft): Payment {
30
+ const resource: Payment = {
31
+ ...getBaseResourceProperties(),
32
+ amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
33
+ paymentMethodInfo: draft.paymentMethodInfo!,
34
+ paymentStatus: draft.paymentStatus
35
+ ? {
36
+ ...draft.paymentStatus,
37
+ state: draft.paymentStatus.state
38
+ ? getReferenceFromResourceIdentifier<StateReference>(
39
+ draft.paymentStatus.state,
40
+ context.projectKey,
41
+ this._storage
42
+ )
43
+ : undefined,
44
+ }
45
+ : {},
46
+ transactions: (draft.transactions || []).map((t) =>
47
+ this.transactionFromTransactionDraft(t, context)
48
+ ),
49
+ interfaceInteractions: (draft.interfaceInteractions || []).map(
50
+ (interaction) =>
51
+ createCustomFields(interaction, context.projectKey, this._storage)!
52
+ ),
53
+ custom: createCustomFields(
54
+ draft.custom,
55
+ context.projectKey,
56
+ this._storage
57
+ ),
58
+ }
59
59
 
60
- this.saveNew(context, resource)
61
- return resource
62
- }
60
+ this.saveNew(context, resource)
61
+ return resource
62
+ }
63
63
 
64
- transactionFromTransactionDraft = (
65
- draft: TransactionDraft,
66
- context: RepositoryContext
67
- ): Transaction => ({
68
- ...draft,
69
- id: uuidv4(),
70
- amount: createCentPrecisionMoney(draft.amount),
71
- custom: createCustomFields(draft.custom, context.projectKey, this._storage),
72
- state: draft.state ?? 'Initial', // Documented as default
73
- })
64
+ transactionFromTransactionDraft = (
65
+ draft: TransactionDraft,
66
+ context: RepositoryContext
67
+ ): Transaction => ({
68
+ ...draft,
69
+ id: uuidv4(),
70
+ amount: createCentPrecisionMoney(draft.amount),
71
+ custom: createCustomFields(draft.custom, context.projectKey, this._storage),
72
+ state: draft.state ?? 'Initial', // Documented as default
73
+ })
74
74
 
75
- actions = {
76
- setCustomField: (
77
- context: RepositoryContext,
78
- resource: Payment,
79
- { name, value }: PaymentSetCustomFieldAction
80
- ) => {
81
- if (!resource.custom) {
82
- throw new Error('Resource has no custom field')
83
- }
75
+ actions = {
76
+ setCustomField: (
77
+ context: RepositoryContext,
78
+ resource: Payment,
79
+ { name, value }: PaymentSetCustomFieldAction
80
+ ) => {
81
+ if (!resource.custom) {
82
+ throw new Error('Resource has no custom field')
83
+ }
84
84
 
85
- resource.custom.fields[name] = value
86
- },
87
- setCustomType: (
88
- context: RepositoryContext,
89
- resource: Writable<Payment>,
90
- { type, fields }: PaymentSetCustomTypeAction
91
- ) => {
92
- if (!type) {
93
- resource.custom = undefined
94
- } else {
95
- const resolvedType = this._storage.getByResourceIdentifier(
96
- context.projectKey,
97
- type
98
- )
99
- if (!resolvedType) {
100
- throw new Error(`Type ${type} not found`)
101
- }
85
+ resource.custom.fields[name] = value
86
+ },
87
+ setCustomType: (
88
+ context: RepositoryContext,
89
+ resource: Writable<Payment>,
90
+ { type, fields }: PaymentSetCustomTypeAction
91
+ ) => {
92
+ if (!type) {
93
+ resource.custom = undefined
94
+ } else {
95
+ const resolvedType = this._storage.getByResourceIdentifier(
96
+ context.projectKey,
97
+ type
98
+ )
99
+ if (!resolvedType) {
100
+ throw new Error(`Type ${type} not found`)
101
+ }
102
102
 
103
- resource.custom = {
104
- type: {
105
- typeId: 'type',
106
- id: resolvedType.id,
107
- },
108
- fields: fields ?? {},
109
- }
110
- }
111
- },
112
- addTransaction: (
113
- context: RepositoryContext,
114
- resource: Writable<Payment>,
115
- { transaction }: PaymentAddTransactionAction
116
- ) => {
117
- resource.transactions = [
118
- ...resource.transactions,
119
- this.transactionFromTransactionDraft(transaction, context),
120
- ]
121
- },
122
- changeTransactionState: (
123
- _context: RepositoryContext,
124
- resource: Writable<Payment>,
125
- { transactionId, state }: PaymentChangeTransactionStateAction
126
- ) => {
127
- const index = resource.transactions.findIndex(
128
- (e: Transaction) => e.id === transactionId
129
- )
130
- const updatedTransaction: Transaction = {
131
- ...resource.transactions[index],
132
- state,
133
- }
134
- resource.transactions[index] = updatedTransaction
135
- },
136
- transitionState: (
137
- context: RepositoryContext,
138
- resource: Writable<Payment>,
139
- { state }: PaymentTransitionStateAction
140
- ) => {
141
- const stateObj = this._storage.getByResourceIdentifier(
142
- context.projectKey,
143
- state
144
- ) as State | null
103
+ resource.custom = {
104
+ type: {
105
+ typeId: 'type',
106
+ id: resolvedType.id,
107
+ },
108
+ fields: fields ?? {},
109
+ }
110
+ }
111
+ },
112
+ addTransaction: (
113
+ context: RepositoryContext,
114
+ resource: Writable<Payment>,
115
+ { transaction }: PaymentAddTransactionAction
116
+ ) => {
117
+ resource.transactions = [
118
+ ...resource.transactions,
119
+ this.transactionFromTransactionDraft(transaction, context),
120
+ ]
121
+ },
122
+ changeTransactionState: (
123
+ _context: RepositoryContext,
124
+ resource: Writable<Payment>,
125
+ { transactionId, state }: PaymentChangeTransactionStateAction
126
+ ) => {
127
+ const index = resource.transactions.findIndex(
128
+ (e: Transaction) => e.id === transactionId
129
+ )
130
+ const updatedTransaction: Transaction = {
131
+ ...resource.transactions[index],
132
+ state,
133
+ }
134
+ resource.transactions[index] = updatedTransaction
135
+ },
136
+ transitionState: (
137
+ context: RepositoryContext,
138
+ resource: Writable<Payment>,
139
+ { state }: PaymentTransitionStateAction
140
+ ) => {
141
+ const stateObj = this._storage.getByResourceIdentifier(
142
+ context.projectKey,
143
+ state
144
+ ) as State | null
145
145
 
146
- if (!stateObj) {
147
- throw new Error(`State ${state} not found`)
148
- }
146
+ if (!stateObj) {
147
+ throw new Error(`State ${state} not found`)
148
+ }
149
149
 
150
- resource.paymentStatus.state = {
151
- typeId: 'state',
152
- id: stateObj.id,
153
- obj: stateObj,
154
- }
155
- },
156
- // addInterfaceInteraction: () => {},
157
- // changeAmountPlanned: () => {},
158
- // changeTransactionInteractionId: () => {},
159
- // changeTransactionTimestamp: () => {},
160
- // setAmountPaid: () => {},
161
- // setAmountRefunded: () => {},
162
- // setAnonymousId: () => {},
163
- // setAuthorization: () => {},
164
- // setCustomer: () => {},
165
- // setExternalId: () => {},
166
- // setInterfaceId: () => {},
167
- // setKey: () => {},
168
- // setMethodInfoInterface: () => {},
169
- // setMethodInfoMethod: () => {},
170
- // setMethodInfoName: () => {},
171
- // setStatusInterfaceCode: () => {},
172
- // setStatusInterfaceText: () => {},
173
- }
150
+ resource.paymentStatus.state = {
151
+ typeId: 'state',
152
+ id: stateObj.id,
153
+ obj: stateObj,
154
+ }
155
+ },
156
+ // addInterfaceInteraction: () => {},
157
+ // changeAmountPlanned: () => {},
158
+ // changeTransactionInteractionId: () => {},
159
+ // changeTransactionTimestamp: () => {},
160
+ // setAmountPaid: () => {},
161
+ // setAmountRefunded: () => {},
162
+ // setAnonymousId: () => {},
163
+ // setAuthorization: () => {},
164
+ // setCustomer: () => {},
165
+ // setExternalId: () => {},
166
+ // setInterfaceId: () => {},
167
+ // setKey: () => {},
168
+ // setMethodInfoInterface: () => {},
169
+ // setMethodInfoMethod: () => {},
170
+ // setMethodInfoName: () => {},
171
+ // setStatusInterfaceCode: () => {},
172
+ // setStatusInterfaceText: () => {},
173
+ }
174
174
  }
@@ -1,22 +1,22 @@
1
1
  import type {
2
- ProductDiscount,
3
- ProductDiscountChangeIsActiveAction,
4
- ProductDiscountChangeNameAction,
5
- ProductDiscountChangePredicateAction,
6
- ProductDiscountChangeSortOrderAction,
7
- ProductDiscountChangeValueAction,
8
- ProductDiscountDraft,
9
- ProductDiscountSetDescriptionAction,
10
- ProductDiscountSetKeyAction,
11
- ProductDiscountSetValidFromAction,
12
- ProductDiscountSetValidFromAndUntilAction,
13
- ProductDiscountSetValidUntilAction,
14
- ProductDiscountUpdateAction,
15
- ProductDiscountValue,
16
- ProductDiscountValueAbsolute,
17
- ProductDiscountValueDraft,
18
- ProductDiscountValueExternal,
19
- ProductDiscountValueRelative,
2
+ ProductDiscount,
3
+ ProductDiscountChangeIsActiveAction,
4
+ ProductDiscountChangeNameAction,
5
+ ProductDiscountChangePredicateAction,
6
+ ProductDiscountChangeSortOrderAction,
7
+ ProductDiscountChangeValueAction,
8
+ ProductDiscountDraft,
9
+ ProductDiscountSetDescriptionAction,
10
+ ProductDiscountSetKeyAction,
11
+ ProductDiscountSetValidFromAction,
12
+ ProductDiscountSetValidFromAndUntilAction,
13
+ ProductDiscountSetValidUntilAction,
14
+ ProductDiscountUpdateAction,
15
+ ProductDiscountValue,
16
+ ProductDiscountValueAbsolute,
17
+ ProductDiscountValueDraft,
18
+ ProductDiscountValueExternal,
19
+ ProductDiscountValueRelative,
20
20
  } from '@commercetools/platform-sdk'
21
21
  import { getBaseResourceProperties } from '../helpers.js'
22
22
  import type { Writable } from '../types.js'
@@ -24,138 +24,138 @@ import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
24
24
  import { createTypedMoney } from './helpers.js'
25
25
 
26
26
  export class ProductDiscountRepository extends AbstractResourceRepository<'product-discount'> {
27
- getTypeId() {
28
- return 'product-discount' as const
29
- }
27
+ getTypeId() {
28
+ return 'product-discount' as const
29
+ }
30
30
 
31
- create(
32
- context: RepositoryContext,
33
- draft: ProductDiscountDraft
34
- ): ProductDiscount {
35
- const resource: ProductDiscount = {
36
- ...getBaseResourceProperties(),
37
- key: draft.key,
38
- name: draft.name,
39
- description: draft.description,
40
- value: this.transformValueDraft(draft.value),
41
- predicate: draft.predicate,
42
- sortOrder: draft.sortOrder,
43
- isActive: draft.isActive || false,
44
- validFrom: draft.validFrom,
45
- validUntil: draft.validUntil,
46
- references: [],
47
- }
48
- this.saveNew(context, resource)
49
- return resource
50
- }
31
+ create(
32
+ context: RepositoryContext,
33
+ draft: ProductDiscountDraft
34
+ ): ProductDiscount {
35
+ const resource: ProductDiscount = {
36
+ ...getBaseResourceProperties(),
37
+ key: draft.key,
38
+ name: draft.name,
39
+ description: draft.description,
40
+ value: this.transformValueDraft(draft.value),
41
+ predicate: draft.predicate,
42
+ sortOrder: draft.sortOrder,
43
+ isActive: draft.isActive || false,
44
+ validFrom: draft.validFrom,
45
+ validUntil: draft.validUntil,
46
+ references: [],
47
+ }
48
+ this.saveNew(context, resource)
49
+ return resource
50
+ }
51
51
 
52
- private transformValueDraft(
53
- value: ProductDiscountValueDraft
54
- ): ProductDiscountValue {
55
- switch (value.type) {
56
- case 'absolute': {
57
- return {
58
- type: 'absolute',
59
- money: value.money.map(createTypedMoney),
60
- } as ProductDiscountValueAbsolute
61
- }
62
- case 'external': {
63
- return {
64
- type: 'external',
65
- } as ProductDiscountValueExternal
66
- }
67
- case 'relative': {
68
- return {
69
- ...value,
70
- } as ProductDiscountValueRelative
71
- }
72
- }
73
- }
52
+ private transformValueDraft(
53
+ value: ProductDiscountValueDraft
54
+ ): ProductDiscountValue {
55
+ switch (value.type) {
56
+ case 'absolute': {
57
+ return {
58
+ type: 'absolute',
59
+ money: value.money.map(createTypedMoney),
60
+ } as ProductDiscountValueAbsolute
61
+ }
62
+ case 'external': {
63
+ return {
64
+ type: 'external',
65
+ } as ProductDiscountValueExternal
66
+ }
67
+ case 'relative': {
68
+ return {
69
+ ...value,
70
+ } as ProductDiscountValueRelative
71
+ }
72
+ }
73
+ }
74
74
 
75
- actions: Partial<
76
- Record<
77
- ProductDiscountUpdateAction['action'],
78
- (
79
- context: RepositoryContext,
80
- resource: Writable<ProductDiscount>,
81
- action: any
82
- ) => void
83
- >
84
- > = {
85
- setKey: (
86
- context: RepositoryContext,
87
- resource: Writable<ProductDiscount>,
88
- { key }: ProductDiscountSetKeyAction
89
- ) => {
90
- resource.key = key
91
- },
92
- setDescription: (
93
- context: RepositoryContext,
94
- resource: Writable<ProductDiscount>,
95
- { description }: ProductDiscountSetDescriptionAction
96
- ) => {
97
- if (description && Object.keys(description).length > 0) {
98
- resource.description = description
99
- } else {
100
- resource.description = undefined
101
- }
102
- },
103
- changeName: (
104
- context: RepositoryContext,
105
- resource: Writable<ProductDiscount>,
106
- { name }: ProductDiscountChangeNameAction
107
- ) => {
108
- resource.name = name
109
- },
110
- changeValue: (
111
- context: RepositoryContext,
112
- resource: Writable<ProductDiscount>,
113
- { value }: ProductDiscountChangeValueAction
114
- ) => {
115
- resource.value = this.transformValueDraft(value)
116
- },
117
- changePredicate: (
118
- context: RepositoryContext,
119
- resource: Writable<ProductDiscount>,
120
- { predicate }: ProductDiscountChangePredicateAction
121
- ) => {
122
- resource.predicate = predicate
123
- },
124
- changeSortOrder: (
125
- context: RepositoryContext,
126
- resource: Writable<ProductDiscount>,
127
- { sortOrder }: ProductDiscountChangeSortOrderAction
128
- ) => {
129
- resource.sortOrder = sortOrder
130
- },
131
- changeIsActive: (
132
- context: RepositoryContext,
133
- resource: Writable<ProductDiscount>,
134
- { isActive }: ProductDiscountChangeIsActiveAction
135
- ) => {
136
- resource.isActive = isActive
137
- },
138
- setValidFrom: (
139
- context: RepositoryContext,
140
- resource: Writable<ProductDiscount>,
141
- { validFrom }: ProductDiscountSetValidFromAction
142
- ) => {
143
- resource.validFrom = validFrom
144
- },
145
- setValidUntil: (
146
- context: RepositoryContext,
147
- resource: Writable<ProductDiscount>,
148
- { validUntil }: ProductDiscountSetValidUntilAction
149
- ) => {
150
- resource.validUntil = validUntil
151
- },
152
- setValidFromAndUntil: (
153
- context: RepositoryContext,
154
- resource: Writable<ProductDiscount>,
155
- { validFrom, validUntil }: ProductDiscountSetValidFromAndUntilAction
156
- ) => {
157
- resource.validFrom = validFrom
158
- resource.validUntil = validUntil
159
- },
160
- }
75
+ actions: Partial<
76
+ Record<
77
+ ProductDiscountUpdateAction['action'],
78
+ (
79
+ context: RepositoryContext,
80
+ resource: Writable<ProductDiscount>,
81
+ action: any
82
+ ) => void
83
+ >
84
+ > = {
85
+ setKey: (
86
+ context: RepositoryContext,
87
+ resource: Writable<ProductDiscount>,
88
+ { key }: ProductDiscountSetKeyAction
89
+ ) => {
90
+ resource.key = key
91
+ },
92
+ setDescription: (
93
+ context: RepositoryContext,
94
+ resource: Writable<ProductDiscount>,
95
+ { description }: ProductDiscountSetDescriptionAction
96
+ ) => {
97
+ if (description && Object.keys(description).length > 0) {
98
+ resource.description = description
99
+ } else {
100
+ resource.description = undefined
101
+ }
102
+ },
103
+ changeName: (
104
+ context: RepositoryContext,
105
+ resource: Writable<ProductDiscount>,
106
+ { name }: ProductDiscountChangeNameAction
107
+ ) => {
108
+ resource.name = name
109
+ },
110
+ changeValue: (
111
+ context: RepositoryContext,
112
+ resource: Writable<ProductDiscount>,
113
+ { value }: ProductDiscountChangeValueAction
114
+ ) => {
115
+ resource.value = this.transformValueDraft(value)
116
+ },
117
+ changePredicate: (
118
+ context: RepositoryContext,
119
+ resource: Writable<ProductDiscount>,
120
+ { predicate }: ProductDiscountChangePredicateAction
121
+ ) => {
122
+ resource.predicate = predicate
123
+ },
124
+ changeSortOrder: (
125
+ context: RepositoryContext,
126
+ resource: Writable<ProductDiscount>,
127
+ { sortOrder }: ProductDiscountChangeSortOrderAction
128
+ ) => {
129
+ resource.sortOrder = sortOrder
130
+ },
131
+ changeIsActive: (
132
+ context: RepositoryContext,
133
+ resource: Writable<ProductDiscount>,
134
+ { isActive }: ProductDiscountChangeIsActiveAction
135
+ ) => {
136
+ resource.isActive = isActive
137
+ },
138
+ setValidFrom: (
139
+ context: RepositoryContext,
140
+ resource: Writable<ProductDiscount>,
141
+ { validFrom }: ProductDiscountSetValidFromAction
142
+ ) => {
143
+ resource.validFrom = validFrom
144
+ },
145
+ setValidUntil: (
146
+ context: RepositoryContext,
147
+ resource: Writable<ProductDiscount>,
148
+ { validUntil }: ProductDiscountSetValidUntilAction
149
+ ) => {
150
+ resource.validUntil = validUntil
151
+ },
152
+ setValidFromAndUntil: (
153
+ context: RepositoryContext,
154
+ resource: Writable<ProductDiscount>,
155
+ { validFrom, validUntil }: ProductDiscountSetValidFromAndUntilAction
156
+ ) => {
157
+ resource.validFrom = validFrom
158
+ resource.validUntil = validUntil
159
+ },
160
+ }
161
161
  }