@labdigital/commercetools-mock 2.17.1 → 2.18.1
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 +4351 -4099
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4351 -4099
- package/dist/index.js.map +1 -1
- package/package.json +47 -47
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/schemas/update-request.ts +12 -0
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +85 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +23 -36
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +66 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +29 -24
- package/src/services/project.ts +22 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/validate.ts +18 -0
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CustomerReference,
|
|
3
|
-
Payment,
|
|
4
|
-
PaymentAddInterfaceInteractionAction,
|
|
5
|
-
PaymentAddTransactionAction,
|
|
6
|
-
PaymentChangeAmountPlannedAction,
|
|
7
|
-
PaymentChangeTransactionInteractionIdAction,
|
|
8
|
-
PaymentChangeTransactionStateAction,
|
|
9
|
-
PaymentChangeTransactionTimestampAction,
|
|
10
|
-
PaymentDraft,
|
|
11
|
-
PaymentSetAnonymousIdAction,
|
|
12
|
-
PaymentSetCustomFieldAction,
|
|
13
|
-
PaymentSetCustomTypeAction,
|
|
14
|
-
PaymentSetCustomerAction,
|
|
15
|
-
PaymentSetInterfaceIdAction,
|
|
16
|
-
PaymentSetKeyAction,
|
|
17
|
-
PaymentSetMethodInfoInterfaceAction,
|
|
18
|
-
PaymentSetMethodInfoMethodAction,
|
|
19
|
-
PaymentSetMethodInfoNameAction,
|
|
20
|
-
PaymentSetStatusInterfaceCodeAction,
|
|
21
|
-
PaymentSetStatusInterfaceTextAction,
|
|
22
|
-
PaymentSetTransactionCustomFieldAction,
|
|
23
|
-
PaymentSetTransactionCustomTypeAction,
|
|
24
|
-
PaymentTransitionStateAction,
|
|
25
|
-
PaymentUpdateAction,
|
|
26
|
-
State,
|
|
27
|
-
StateReference,
|
|
28
|
-
Transaction,
|
|
29
|
-
TransactionDraft,
|
|
30
|
-
} from '@commercetools/platform-sdk'
|
|
31
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
32
|
-
import { getBaseResourceProperties } from '../helpers.js'
|
|
33
|
-
import type { Writable } from '../types.js'
|
|
34
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
35
|
-
import {
|
|
36
|
-
createCentPrecisionMoney,
|
|
37
|
-
createCustomFields,
|
|
38
|
-
getReferenceFromResourceIdentifier,
|
|
39
|
-
} from './helpers.js'
|
|
40
|
-
|
|
41
|
-
export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
42
|
-
getTypeId() {
|
|
43
|
-
return 'payment' as const
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
create(context: RepositoryContext, draft: PaymentDraft): Payment {
|
|
47
|
-
const resource: Payment = {
|
|
48
|
-
...getBaseResourceProperties(),
|
|
49
|
-
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
50
|
-
paymentMethodInfo: draft.paymentMethodInfo!,
|
|
51
|
-
paymentStatus: draft.paymentStatus
|
|
52
|
-
? {
|
|
53
|
-
...draft.paymentStatus,
|
|
54
|
-
state: draft.paymentStatus.state
|
|
55
|
-
? getReferenceFromResourceIdentifier<StateReference>(
|
|
56
|
-
draft.paymentStatus.state,
|
|
57
|
-
context.projectKey,
|
|
58
|
-
this._storage
|
|
59
|
-
)
|
|
60
|
-
: undefined,
|
|
61
|
-
}
|
|
62
|
-
: {},
|
|
63
|
-
transactions: (draft.transactions || []).map((t) =>
|
|
64
|
-
this.transactionFromTransactionDraft(t, context)
|
|
65
|
-
),
|
|
66
|
-
interfaceInteractions: (draft.interfaceInteractions || []).map(
|
|
67
|
-
(interaction) =>
|
|
68
|
-
createCustomFields(interaction, context.projectKey, this._storage)!
|
|
69
|
-
),
|
|
70
|
-
custom: createCustomFields(
|
|
71
|
-
draft.custom,
|
|
72
|
-
context.projectKey,
|
|
73
|
-
this._storage
|
|
74
|
-
),
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.saveNew(context, resource)
|
|
78
|
-
return resource
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
transactionFromTransactionDraft = (
|
|
82
|
-
draft: TransactionDraft,
|
|
83
|
-
context: RepositoryContext
|
|
84
|
-
): Transaction => ({
|
|
85
|
-
...draft,
|
|
86
|
-
id: uuidv4(),
|
|
87
|
-
amount: createCentPrecisionMoney(draft.amount),
|
|
88
|
-
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
89
|
-
state: draft.state ?? 'Initial', // Documented as default
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
actions: Record<
|
|
93
|
-
PaymentUpdateAction['action'],
|
|
94
|
-
(
|
|
95
|
-
context: RepositoryContext,
|
|
96
|
-
resource: Writable<Payment>,
|
|
97
|
-
action: any
|
|
98
|
-
) => void
|
|
99
|
-
> = {
|
|
100
|
-
addInterfaceInteraction: (
|
|
101
|
-
context: RepositoryContext,
|
|
102
|
-
resource: Writable<Payment>,
|
|
103
|
-
{ type, fields }: PaymentAddInterfaceInteractionAction
|
|
104
|
-
) => {
|
|
105
|
-
resource.interfaceInteractions.push(
|
|
106
|
-
createCustomFields({ type, fields }, context.projectKey, this._storage)!
|
|
107
|
-
)
|
|
108
|
-
},
|
|
109
|
-
addTransaction: (
|
|
110
|
-
context: RepositoryContext,
|
|
111
|
-
resource: Writable<Payment>,
|
|
112
|
-
{ transaction }: PaymentAddTransactionAction
|
|
113
|
-
) => {
|
|
114
|
-
resource.transactions = [
|
|
115
|
-
...resource.transactions,
|
|
116
|
-
this.transactionFromTransactionDraft(transaction, context),
|
|
117
|
-
]
|
|
118
|
-
},
|
|
119
|
-
changeAmountPlanned: (
|
|
120
|
-
_context: RepositoryContext,
|
|
121
|
-
resource: Writable<Payment>,
|
|
122
|
-
{ amount }: PaymentChangeAmountPlannedAction
|
|
123
|
-
) => {
|
|
124
|
-
resource.amountPlanned = createCentPrecisionMoney(amount)
|
|
125
|
-
},
|
|
126
|
-
changeTransactionInteractionId: (
|
|
127
|
-
_context: RepositoryContext,
|
|
128
|
-
resource: Writable<Payment>,
|
|
129
|
-
{
|
|
130
|
-
transactionId,
|
|
131
|
-
interactionId,
|
|
132
|
-
}: PaymentChangeTransactionInteractionIdAction
|
|
133
|
-
) => {
|
|
134
|
-
const transaction = resource.transactions.find(
|
|
135
|
-
(e: Transaction) => e.id === transactionId
|
|
136
|
-
)
|
|
137
|
-
if (transaction) {
|
|
138
|
-
transaction.interactionId = interactionId
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
changeTransactionState: (
|
|
142
|
-
_context: RepositoryContext,
|
|
143
|
-
resource: Writable<Payment>,
|
|
144
|
-
{ transactionId, state }: PaymentChangeTransactionStateAction
|
|
145
|
-
) => {
|
|
146
|
-
const index = resource.transactions.findIndex(
|
|
147
|
-
(e: Transaction) => e.id === transactionId
|
|
148
|
-
)
|
|
149
|
-
const updatedTransaction: Transaction = {
|
|
150
|
-
...resource.transactions[index],
|
|
151
|
-
state,
|
|
152
|
-
}
|
|
153
|
-
resource.transactions[index] = updatedTransaction
|
|
154
|
-
},
|
|
155
|
-
changeTransactionTimestamp: (
|
|
156
|
-
_context: RepositoryContext,
|
|
157
|
-
resource: Writable<Payment>,
|
|
158
|
-
{ transactionId, timestamp }: PaymentChangeTransactionTimestampAction
|
|
159
|
-
) => {
|
|
160
|
-
const transaction = resource.transactions.find(
|
|
161
|
-
(e: Transaction) => e.id === transactionId
|
|
162
|
-
)
|
|
163
|
-
if (transaction) {
|
|
164
|
-
transaction.timestamp = timestamp
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
transitionState: (
|
|
168
|
-
context: RepositoryContext,
|
|
169
|
-
resource: Writable<Payment>,
|
|
170
|
-
{ state }: PaymentTransitionStateAction
|
|
171
|
-
) => {
|
|
172
|
-
const stateObj = this._storage.getByResourceIdentifier(
|
|
173
|
-
context.projectKey,
|
|
174
|
-
state
|
|
175
|
-
) as State | null
|
|
176
|
-
|
|
177
|
-
if (!stateObj) {
|
|
178
|
-
throw new Error(`State ${state} not found`)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
resource.paymentStatus.state = {
|
|
182
|
-
typeId: 'state',
|
|
183
|
-
id: stateObj.id,
|
|
184
|
-
obj: stateObj,
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
setAnonymousId: (
|
|
188
|
-
_context: RepositoryContext,
|
|
189
|
-
resource: Writable<Payment>,
|
|
190
|
-
{ anonymousId }: PaymentSetAnonymousIdAction
|
|
191
|
-
) => {
|
|
192
|
-
resource.anonymousId = anonymousId
|
|
193
|
-
resource.customer = undefined
|
|
194
|
-
},
|
|
195
|
-
setCustomer: (
|
|
196
|
-
_context: RepositoryContext,
|
|
197
|
-
resource: Writable<Payment>,
|
|
198
|
-
{ customer }: PaymentSetCustomerAction
|
|
199
|
-
) => {
|
|
200
|
-
if (customer) {
|
|
201
|
-
const c = getReferenceFromResourceIdentifier<CustomerReference>(
|
|
202
|
-
customer,
|
|
203
|
-
_context.projectKey,
|
|
204
|
-
this._storage
|
|
205
|
-
)
|
|
206
|
-
resource.customer = c
|
|
207
|
-
resource.anonymousId = undefined
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
setCustomField: (
|
|
211
|
-
context: RepositoryContext,
|
|
212
|
-
resource: Payment,
|
|
213
|
-
{ name, value }: PaymentSetCustomFieldAction
|
|
214
|
-
) => {
|
|
215
|
-
if (!resource.custom) {
|
|
216
|
-
throw new Error('Resource has no custom field')
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
resource.custom.fields[name] = value
|
|
220
|
-
},
|
|
221
|
-
setCustomType: (
|
|
222
|
-
context: RepositoryContext,
|
|
223
|
-
resource: Writable<Payment>,
|
|
224
|
-
{ type, fields }: PaymentSetCustomTypeAction
|
|
225
|
-
) => {
|
|
226
|
-
if (!type) {
|
|
227
|
-
resource.custom = undefined
|
|
228
|
-
} else {
|
|
229
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
230
|
-
context.projectKey,
|
|
231
|
-
type
|
|
232
|
-
)
|
|
233
|
-
if (!resolvedType) {
|
|
234
|
-
throw new Error(`Type ${type} not found`)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
resource.custom = {
|
|
238
|
-
type: {
|
|
239
|
-
typeId: 'type',
|
|
240
|
-
id: resolvedType.id,
|
|
241
|
-
},
|
|
242
|
-
fields: fields ?? {},
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
setInterfaceId: (
|
|
247
|
-
_context: RepositoryContext,
|
|
248
|
-
resource: Writable<Payment>,
|
|
249
|
-
{ interfaceId }: PaymentSetInterfaceIdAction
|
|
250
|
-
) => {
|
|
251
|
-
resource.interfaceId = interfaceId
|
|
252
|
-
},
|
|
253
|
-
setKey: (
|
|
254
|
-
_context: RepositoryContext,
|
|
255
|
-
resource: Writable<Payment>,
|
|
256
|
-
{ key }: PaymentSetKeyAction
|
|
257
|
-
) => {
|
|
258
|
-
resource.key = key
|
|
259
|
-
},
|
|
260
|
-
setMethodInfoMethod: (
|
|
261
|
-
_context: RepositoryContext,
|
|
262
|
-
resource: Writable<Payment>,
|
|
263
|
-
{ method }: PaymentSetMethodInfoMethodAction
|
|
264
|
-
) => {
|
|
265
|
-
resource.paymentMethodInfo.method = method
|
|
266
|
-
},
|
|
267
|
-
setMethodInfoName: (
|
|
268
|
-
_context: RepositoryContext,
|
|
269
|
-
resource: Writable<Payment>,
|
|
270
|
-
{ name }: PaymentSetMethodInfoNameAction
|
|
271
|
-
) => {
|
|
272
|
-
resource.paymentMethodInfo.name = name
|
|
273
|
-
},
|
|
274
|
-
setMethodInfoInterface: (
|
|
275
|
-
_context: RepositoryContext,
|
|
276
|
-
resource: Writable<Payment>,
|
|
277
|
-
args: PaymentSetMethodInfoInterfaceAction
|
|
278
|
-
) => {
|
|
279
|
-
resource.paymentMethodInfo.paymentInterface = args.interface
|
|
280
|
-
},
|
|
281
|
-
setStatusInterfaceCode: (
|
|
282
|
-
_context: RepositoryContext,
|
|
283
|
-
resource: Writable<Payment>,
|
|
284
|
-
{ interfaceCode }: PaymentSetStatusInterfaceCodeAction
|
|
285
|
-
) => {
|
|
286
|
-
resource.paymentStatus.interfaceCode = interfaceCode
|
|
287
|
-
},
|
|
288
|
-
setStatusInterfaceText: (
|
|
289
|
-
_context: RepositoryContext,
|
|
290
|
-
resource: Writable<Payment>,
|
|
291
|
-
{ interfaceText }: PaymentSetStatusInterfaceTextAction
|
|
292
|
-
) => {
|
|
293
|
-
resource.paymentStatus.interfaceText = interfaceText
|
|
294
|
-
},
|
|
295
|
-
setTransactionCustomField: (
|
|
296
|
-
_context: RepositoryContext,
|
|
297
|
-
resource: Writable<Payment>,
|
|
298
|
-
{ transactionId, name, value }: PaymentSetTransactionCustomFieldAction
|
|
299
|
-
) => {
|
|
300
|
-
const transaction = resource.transactions.find(
|
|
301
|
-
(e: Transaction) => e.id === transactionId
|
|
302
|
-
)
|
|
303
|
-
if (transaction) {
|
|
304
|
-
if (!transaction.custom) {
|
|
305
|
-
throw new Error('Transaction has no custom field')
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
transaction.custom.fields[name] = value
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
setTransactionCustomType: (
|
|
312
|
-
context: RepositoryContext,
|
|
313
|
-
resource: Writable<Payment>,
|
|
314
|
-
{ transactionId, type, fields }: PaymentSetTransactionCustomTypeAction
|
|
315
|
-
) => {
|
|
316
|
-
const transaction = resource.transactions.find(
|
|
317
|
-
(e: Transaction) => e.id === transactionId
|
|
318
|
-
)
|
|
319
|
-
if (transaction) {
|
|
320
|
-
if (!type) {
|
|
321
|
-
transaction.custom = undefined
|
|
322
|
-
} else {
|
|
323
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
324
|
-
context.projectKey,
|
|
325
|
-
type
|
|
326
|
-
)
|
|
327
|
-
if (!resolvedType) {
|
|
328
|
-
throw new Error(`Type ${type} not found`)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
transaction.custom = {
|
|
332
|
-
type: {
|
|
333
|
-
typeId: 'type',
|
|
334
|
-
id: resolvedType.id,
|
|
335
|
-
},
|
|
336
|
-
fields: fields ?? {},
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
}
|
|
342
|
-
}
|