@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.
- package/README.md +5 -4
- package/dist/index.cjs +105 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -7
- package/dist/index.d.ts +29 -7
- package/dist/index.js +105 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +90 -90
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +116 -52
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -151
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +492 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
TaxCategory,
|
|
3
|
+
TaxCategoryAddTaxRateAction,
|
|
4
|
+
TaxCategoryChangeNameAction,
|
|
5
|
+
TaxCategoryDraft,
|
|
6
|
+
TaxCategoryRemoveTaxRateAction,
|
|
7
|
+
TaxCategoryReplaceTaxRateAction,
|
|
8
|
+
TaxCategorySetDescriptionAction,
|
|
9
|
+
TaxCategorySetKeyAction,
|
|
10
|
+
TaxCategoryUpdateAction,
|
|
11
|
+
TaxRate,
|
|
12
|
+
TaxRateDraft,
|
|
13
13
|
} from '@commercetools/platform-sdk'
|
|
14
14
|
import { v4 as uuidv4 } from 'uuid'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
@@ -17,95 +17,95 @@ import type { Writable } from '../types.js'
|
|
|
17
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
18
18
|
|
|
19
19
|
export class TaxCategoryRepository extends AbstractResourceRepository<'tax-category'> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'tax-category' as const
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
|
|
25
|
+
const resource: TaxCategory = {
|
|
26
|
+
...getBaseResourceProperties(),
|
|
27
|
+
...draft,
|
|
28
|
+
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || [],
|
|
29
|
+
}
|
|
30
|
+
this.saveNew(context, resource)
|
|
31
|
+
return resource
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
private taxRateFromTaxRateDraft = (draft: TaxRateDraft): TaxRate => ({
|
|
35
|
+
...draft,
|
|
36
|
+
id: uuidv4(),
|
|
37
|
+
amount: draft.amount || 0,
|
|
38
|
+
})
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
40
|
+
actions: Partial<
|
|
41
|
+
Record<
|
|
42
|
+
TaxCategoryUpdateAction['action'],
|
|
43
|
+
(
|
|
44
|
+
context: RepositoryContext,
|
|
45
|
+
resource: Writable<TaxCategory>,
|
|
46
|
+
action: any
|
|
47
|
+
) => void
|
|
48
|
+
>
|
|
49
|
+
> = {
|
|
50
|
+
addTaxRate: (
|
|
51
|
+
context: RepositoryContext,
|
|
52
|
+
resource: Writable<TaxCategory>,
|
|
53
|
+
{ taxRate }: TaxCategoryAddTaxRateAction
|
|
54
|
+
) => {
|
|
55
|
+
if (resource.rates === undefined) {
|
|
56
|
+
resource.rates = []
|
|
57
|
+
}
|
|
58
|
+
resource.rates.push(this.taxRateFromTaxRateDraft(taxRate))
|
|
59
|
+
},
|
|
60
|
+
removeTaxRate: (
|
|
61
|
+
context: RepositoryContext,
|
|
62
|
+
resource: Writable<TaxCategory>,
|
|
63
|
+
{ taxRateId }: TaxCategoryRemoveTaxRateAction
|
|
64
|
+
) => {
|
|
65
|
+
if (resource.rates === undefined) {
|
|
66
|
+
resource.rates = []
|
|
67
|
+
}
|
|
68
|
+
resource.rates = resource.rates.filter(
|
|
69
|
+
(taxRate) => taxRate.id !== taxRateId
|
|
70
|
+
)
|
|
71
|
+
},
|
|
72
|
+
replaceTaxRate: (
|
|
73
|
+
context: RepositoryContext,
|
|
74
|
+
resource: Writable<TaxCategory>,
|
|
75
|
+
{ taxRateId, taxRate }: TaxCategoryReplaceTaxRateAction
|
|
76
|
+
) => {
|
|
77
|
+
if (resource.rates === undefined) {
|
|
78
|
+
resource.rates = []
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
const taxRateObj = this.taxRateFromTaxRateDraft(taxRate)
|
|
82
|
+
for (let i = 0; i < resource.rates.length; i++) {
|
|
83
|
+
const rate = resource.rates[i]
|
|
84
|
+
if (rate.id === taxRateId) {
|
|
85
|
+
resource.rates[i] = taxRateObj
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
setDescription: (
|
|
90
|
+
context: RepositoryContext,
|
|
91
|
+
resource: Writable<TaxCategory>,
|
|
92
|
+
{ description }: TaxCategorySetDescriptionAction
|
|
93
|
+
) => {
|
|
94
|
+
resource.description = description
|
|
95
|
+
},
|
|
96
|
+
setKey: (
|
|
97
|
+
context: RepositoryContext,
|
|
98
|
+
resource: Writable<TaxCategory>,
|
|
99
|
+
{ key }: TaxCategorySetKeyAction
|
|
100
|
+
) => {
|
|
101
|
+
resource.key = key
|
|
102
|
+
},
|
|
103
|
+
changeName: (
|
|
104
|
+
context: RepositoryContext,
|
|
105
|
+
resource: Writable<TaxCategory>,
|
|
106
|
+
{ name }: TaxCategoryChangeNameAction
|
|
107
|
+
) => {
|
|
108
|
+
resource.name = name
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
111
|
}
|
package/src/repositories/type.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
FieldDefinition,
|
|
3
|
+
InvalidOperationError,
|
|
4
|
+
Type,
|
|
5
|
+
TypeAddEnumValueAction,
|
|
6
|
+
TypeAddFieldDefinitionAction,
|
|
7
|
+
TypeChangeEnumValueLabelAction,
|
|
8
|
+
TypeChangeFieldDefinitionOrderAction,
|
|
9
|
+
TypeChangeNameAction,
|
|
10
|
+
TypeDraft,
|
|
11
|
+
TypeRemoveFieldDefinitionAction,
|
|
12
|
+
TypeSetDescriptionAction,
|
|
13
|
+
TypeUpdateAction,
|
|
14
14
|
} from '@commercetools/platform-sdk'
|
|
15
15
|
import isEqual from 'lodash.isequal'
|
|
16
16
|
import { CommercetoolsError } from '../exceptions.js'
|
|
@@ -19,154 +19,154 @@ import type { Writable } from '../types.js'
|
|
|
19
19
|
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
20
20
|
|
|
21
21
|
export class TypeRepository extends AbstractResourceRepository<'type'> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'type' as const
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
26
|
+
create(context: RepositoryContext, draft: TypeDraft): Type {
|
|
27
|
+
const resource: Type = {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
key: draft.key,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
resourceTypeIds: draft.resourceTypeIds,
|
|
32
|
+
fieldDefinitions: draft.fieldDefinitions || [],
|
|
33
|
+
description: draft.description,
|
|
34
|
+
}
|
|
35
|
+
this.saveNew(context, resource)
|
|
36
|
+
return resource
|
|
37
|
+
}
|
|
38
|
+
actions: Partial<
|
|
39
|
+
Record<
|
|
40
|
+
TypeUpdateAction['action'],
|
|
41
|
+
(
|
|
42
|
+
context: RepositoryContext,
|
|
43
|
+
resource: Writable<Type>,
|
|
44
|
+
action: any
|
|
45
|
+
) => void
|
|
46
|
+
>
|
|
47
|
+
> = {
|
|
48
|
+
addFieldDefinition: (
|
|
49
|
+
context: RepositoryContext,
|
|
50
|
+
resource: Writable<Type>,
|
|
51
|
+
{ fieldDefinition }: TypeAddFieldDefinitionAction
|
|
52
|
+
) => {
|
|
53
|
+
resource.fieldDefinitions.push(fieldDefinition)
|
|
54
|
+
},
|
|
55
|
+
removeFieldDefinition: (
|
|
56
|
+
context: RepositoryContext,
|
|
57
|
+
resource: Writable<Type>,
|
|
58
|
+
{ fieldName }: TypeRemoveFieldDefinitionAction
|
|
59
|
+
) => {
|
|
60
|
+
resource.fieldDefinitions = resource.fieldDefinitions.filter(
|
|
61
|
+
(f) => f.name !== fieldName
|
|
62
|
+
)
|
|
63
|
+
},
|
|
64
|
+
setDescription: (
|
|
65
|
+
context: RepositoryContext,
|
|
66
|
+
resource: Writable<Type>,
|
|
67
|
+
{ description }: TypeSetDescriptionAction
|
|
68
|
+
) => {
|
|
69
|
+
resource.description = description
|
|
70
|
+
},
|
|
71
|
+
changeName: (
|
|
72
|
+
context: RepositoryContext,
|
|
73
|
+
resource: Writable<Type>,
|
|
74
|
+
{ name }: TypeChangeNameAction
|
|
75
|
+
) => {
|
|
76
|
+
resource.name = name
|
|
77
|
+
},
|
|
78
|
+
changeFieldDefinitionOrder: (
|
|
79
|
+
context: RepositoryContext,
|
|
80
|
+
resource: Writable<Type>,
|
|
81
|
+
{ fieldNames }: TypeChangeFieldDefinitionOrderAction
|
|
82
|
+
) => {
|
|
83
|
+
const fields = new Map(
|
|
84
|
+
resource.fieldDefinitions.map((item) => [item.name, item])
|
|
85
|
+
)
|
|
86
|
+
const result: FieldDefinition[] = []
|
|
87
|
+
let current = resource.fieldDefinitions
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
fieldNames.forEach((fieldName) => {
|
|
90
|
+
const field = fields.get(fieldName)
|
|
91
|
+
if (field === undefined) {
|
|
92
|
+
throw new Error('New field')
|
|
93
|
+
}
|
|
94
|
+
result.push(field)
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
// Remove from current items
|
|
97
|
+
current = current.filter((f) => f.name !== fieldName)
|
|
98
|
+
})
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
if (
|
|
101
|
+
isEqual(
|
|
102
|
+
fieldNames,
|
|
103
|
+
resource.fieldDefinitions.map((item) => item.name)
|
|
104
|
+
)
|
|
105
|
+
) {
|
|
106
|
+
throw new CommercetoolsError<InvalidOperationError>({
|
|
107
|
+
code: 'InvalidOperation',
|
|
108
|
+
message: "'fieldDefinitions' has no changes.",
|
|
109
|
+
action: {
|
|
110
|
+
action: 'changeFieldDefinitionOrder',
|
|
111
|
+
fieldNames: fieldNames,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
116
|
+
resource.fieldDefinitions = result
|
|
117
|
+
// Add fields which were not specified in the order as last items. Not
|
|
118
|
+
// sure if this follows commercetools
|
|
119
|
+
resource.fieldDefinitions.push(...current)
|
|
120
|
+
},
|
|
121
|
+
addEnumValue: (
|
|
122
|
+
context: RepositoryContext,
|
|
123
|
+
resource: Writable<Type>,
|
|
124
|
+
{ fieldName, value }: TypeAddEnumValueAction
|
|
125
|
+
) => {
|
|
126
|
+
resource.fieldDefinitions.forEach((field) => {
|
|
127
|
+
if (field.name === fieldName) {
|
|
128
|
+
// TODO, should be done better i suppose
|
|
129
|
+
if (field.type.name === 'Enum') {
|
|
130
|
+
field.type.values.push(value)
|
|
131
|
+
} else if (
|
|
132
|
+
field.type.name === 'Set' &&
|
|
133
|
+
field.type.elementType.name === 'Enum'
|
|
134
|
+
) {
|
|
135
|
+
field.type.elementType.values.push(value)
|
|
136
|
+
} else {
|
|
137
|
+
throw new Error('Type is not a Enum (or Set of Enum)')
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
},
|
|
142
|
+
changeEnumValueLabel: (
|
|
143
|
+
context: RepositoryContext,
|
|
144
|
+
resource: Writable<Type>,
|
|
145
|
+
{ fieldName, value }: TypeChangeEnumValueLabelAction
|
|
146
|
+
) => {
|
|
147
|
+
resource.fieldDefinitions.forEach((field) => {
|
|
148
|
+
if (field.name === fieldName) {
|
|
149
|
+
// TODO, should be done better i suppose
|
|
150
|
+
if (field.type.name === 'Enum') {
|
|
151
|
+
field.type.values.forEach((v) => {
|
|
152
|
+
if (v.key === value.key) {
|
|
153
|
+
v.label = value.label
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
} else if (
|
|
157
|
+
field.type.name === 'Set' &&
|
|
158
|
+
field.type.elementType.name === 'Enum'
|
|
159
|
+
) {
|
|
160
|
+
field.type.elementType.values.forEach((v) => {
|
|
161
|
+
if (v.key === value.key) {
|
|
162
|
+
v.label = value.label
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
} else {
|
|
166
|
+
throw new Error('Type is not a Enum (or Set of Enum)')
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
172
|
}
|