@labdigital/commercetools-mock 1.4.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 +116 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +116 -18
- 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 +93 -79
- 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 -389
- 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 -129
- 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,59 +1,123 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
InvalidInputError,
|
|
3
|
+
ProductDraft,
|
|
4
|
+
ProductProjection,
|
|
5
|
+
QueryParam,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
2
7
|
import { ParsedQs } from 'qs'
|
|
3
8
|
import { QueryParamsAsArray } from '../helpers.js'
|
|
4
9
|
import { ProductProjectionSearch } from '../product-projection-search.js'
|
|
5
10
|
import { type AbstractStorage } from '../storage/index.js'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
12
|
+
import { parseQueryExpression } from '../lib/predicateParser.js'
|
|
13
|
+
import { CommercetoolsError } from '../exceptions.js'
|
|
14
|
+
|
|
15
|
+
type ProductProjectionQueryParams = {
|
|
16
|
+
staged?: boolean
|
|
17
|
+
priceCurrency?: string
|
|
18
|
+
priceCountry?: string
|
|
19
|
+
priceCustomerGroup?: string
|
|
20
|
+
priceChannel?: string
|
|
21
|
+
localeProjection?: string | string[]
|
|
22
|
+
storeProjection?: string
|
|
23
|
+
expand?: string | string[]
|
|
24
|
+
sort?: string | string[]
|
|
25
|
+
limit?: number
|
|
26
|
+
offset?: number
|
|
27
|
+
withTotal?: boolean
|
|
28
|
+
where?: string | string[]
|
|
29
|
+
[key: string]: QueryParam
|
|
30
|
+
}
|
|
11
31
|
|
|
12
32
|
export class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
33
|
+
protected _searchService: ProductProjectionSearch
|
|
34
|
+
|
|
35
|
+
constructor(storage: AbstractStorage) {
|
|
36
|
+
super(storage)
|
|
37
|
+
this._searchService = new ProductProjectionSearch(storage)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getTypeId() {
|
|
41
|
+
return 'product-projection' as const
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
create(context: RepositoryContext, draft: ProductDraft): ProductProjection {
|
|
45
|
+
throw new Error('No valid action')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
query(context: RepositoryContext, params: ProductProjectionQueryParams = {}) {
|
|
49
|
+
let resources = this._storage
|
|
50
|
+
.all(context.projectKey, 'product')
|
|
51
|
+
.map((r) => this._searchService.transform(r, params.staged ?? false))
|
|
52
|
+
.filter((p) => {
|
|
53
|
+
if (!params.staged ?? false) {
|
|
54
|
+
return p.published
|
|
55
|
+
}
|
|
56
|
+
return true
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Apply predicates
|
|
60
|
+
if (params.where) {
|
|
61
|
+
const variableMap: Record<string, QueryParam> = {}
|
|
62
|
+
for (const [k, v] of Object.entries(params)) {
|
|
63
|
+
if (k.startsWith('var.')) {
|
|
64
|
+
variableMap[k.substring(4)] = v
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const filterFunc = parseQueryExpression(params.where)
|
|
70
|
+
resources = resources.filter((resource) =>
|
|
71
|
+
filterFunc(resource, variableMap)
|
|
72
|
+
)
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new CommercetoolsError<InvalidInputError>(
|
|
75
|
+
{
|
|
76
|
+
code: 'InvalidInput',
|
|
77
|
+
message: (err as any).message,
|
|
78
|
+
},
|
|
79
|
+
400
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Expand the resources
|
|
85
|
+
if (params.expand !== undefined) {
|
|
86
|
+
resources = resources.map((resource) =>
|
|
87
|
+
this._storage.expand(context.projectKey, resource, params.expand)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Create a slice for the pagination. If we were working with large datasets
|
|
92
|
+
// then we should have done this before transforming. But that isn't the
|
|
93
|
+
// goal of this library. So lets keep it simple.
|
|
94
|
+
const totalResults = resources.length
|
|
95
|
+
const offset = params.offset || 0
|
|
96
|
+
const limit = params.limit || 20
|
|
97
|
+
const results = resources.slice(offset, offset + limit)
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
count: totalResults,
|
|
101
|
+
total: results.length,
|
|
102
|
+
offset: offset,
|
|
103
|
+
limit: limit,
|
|
104
|
+
results: results,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
search(context: RepositoryContext, query: ParsedQs) {
|
|
109
|
+
const results = this._searchService.search(context.projectKey, {
|
|
110
|
+
filter: QueryParamsAsArray(query.filter),
|
|
111
|
+
'filter.query': QueryParamsAsArray(query['filter.query']),
|
|
112
|
+
facet: QueryParamsAsArray(query.facet),
|
|
113
|
+
offset: query.offset ? Number(query.offset) : undefined,
|
|
114
|
+
limit: query.limit ? Number(query.limit) : undefined,
|
|
115
|
+
expand: QueryParamsAsArray(query.expand),
|
|
116
|
+
staged: query.staged === 'true',
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return results
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
actions = {}
|
|
59
123
|
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
ProductSelection,
|
|
3
|
+
ProductSelectionDraft,
|
|
4
|
+
Review,
|
|
5
|
+
ReviewUpdateAction,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
8
8
|
import type { Writable } from '../types.js'
|
|
9
9
|
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
10
10
|
|
|
11
11
|
export class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
getTypeId() {
|
|
13
|
+
return 'product-selection' as const
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
create(
|
|
17
|
+
context: RepositoryContext,
|
|
18
|
+
draft: ProductSelectionDraft
|
|
19
|
+
): ProductSelection {
|
|
20
|
+
const resource: ProductSelection = {
|
|
21
|
+
...getBaseResourceProperties(),
|
|
22
|
+
productCount: 0,
|
|
23
|
+
name: draft.name,
|
|
24
|
+
type: 'individual',
|
|
25
|
+
mode: 'Individual',
|
|
26
|
+
}
|
|
27
|
+
this.saveNew(context, resource)
|
|
28
|
+
return resource
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
actions: Partial<
|
|
32
|
+
Record<
|
|
33
|
+
ReviewUpdateAction['action'],
|
|
34
|
+
(
|
|
35
|
+
context: RepositoryContext,
|
|
36
|
+
resource: Writable<Review>,
|
|
37
|
+
action: any
|
|
38
|
+
) => void
|
|
39
|
+
>
|
|
40
|
+
> = {}
|
|
41
41
|
}
|
|
@@ -1,173 +1,173 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
AttributeDefinition,
|
|
3
|
+
AttributeDefinitionDraft,
|
|
4
|
+
AttributeType,
|
|
5
|
+
ProductType,
|
|
6
|
+
ProductTypeAddAttributeDefinitionAction,
|
|
7
|
+
ProductTypeChangeAttributeOrderByNameAction,
|
|
8
|
+
ProductTypeChangeLabelAction,
|
|
9
|
+
ProductTypeChangeLocalizedEnumValueLabelAction,
|
|
10
|
+
ProductTypeDraft,
|
|
11
|
+
ProductTypeRemoveAttributeDefinitionAction,
|
|
12
|
+
ProductTypeRemoveEnumValuesAction,
|
|
13
|
+
ProductTypeUpdateAction,
|
|
14
14
|
} from '@commercetools/platform-sdk'
|
|
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
|
|
|
19
19
|
export class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'product-type' as const
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
create(context: RepositoryContext, draft: ProductTypeDraft): ProductType {
|
|
25
|
+
const resource: ProductType = {
|
|
26
|
+
...getBaseResourceProperties(),
|
|
27
|
+
key: draft.key,
|
|
28
|
+
name: draft.name,
|
|
29
|
+
description: draft.description,
|
|
30
|
+
attributes: (draft.attributes ?? []).map((a) =>
|
|
31
|
+
this.attributeDefinitionFromAttributeDefinitionDraft(context, a)
|
|
32
|
+
),
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
this.saveNew(context, resource)
|
|
36
|
+
return resource
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
attributeDefinitionFromAttributeDefinitionDraft = (
|
|
40
|
+
_context: RepositoryContext,
|
|
41
|
+
draft: AttributeDefinitionDraft
|
|
42
|
+
): AttributeDefinition => ({
|
|
43
|
+
...draft,
|
|
44
|
+
attributeConstraint: draft.attributeConstraint ?? 'None',
|
|
45
|
+
inputHint: draft.inputHint ?? 'SingleLine',
|
|
46
|
+
inputTip:
|
|
47
|
+
draft.inputTip && Object.keys(draft.inputTip).length > 0
|
|
48
|
+
? draft.inputTip
|
|
49
|
+
: undefined,
|
|
50
|
+
isSearchable: draft.isSearchable ?? true,
|
|
51
|
+
})
|
|
52
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
|
-
|
|
53
|
+
actions: Partial<
|
|
54
|
+
Record<
|
|
55
|
+
ProductTypeUpdateAction['action'],
|
|
56
|
+
(
|
|
57
|
+
context: RepositoryContext,
|
|
58
|
+
resource: Writable<ProductType>,
|
|
59
|
+
action: any
|
|
60
|
+
) => void
|
|
61
|
+
>
|
|
62
|
+
> = {
|
|
63
|
+
changeLocalizedEnumValueLabel: (
|
|
64
|
+
context: RepositoryContext,
|
|
65
|
+
resource: Writable<ProductType>,
|
|
66
|
+
{
|
|
67
|
+
attributeName,
|
|
68
|
+
newValue,
|
|
69
|
+
}: ProductTypeChangeLocalizedEnumValueLabelAction
|
|
70
|
+
) => {
|
|
71
|
+
const updateAttributeType = (type: Writable<AttributeType>) => {
|
|
72
|
+
switch (type.name) {
|
|
73
|
+
case 'lenum':
|
|
74
|
+
type.values.forEach((v) => {
|
|
75
|
+
if (v.key === newValue.key) {
|
|
76
|
+
v.label = newValue.label
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
return
|
|
80
|
+
case 'set':
|
|
81
|
+
updateAttributeType(type.elementType)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
86
|
+
resource.attributes?.forEach((value) => {
|
|
87
|
+
if (value.name === attributeName) {
|
|
88
|
+
updateAttributeType(value.type)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
changeLabel: (
|
|
93
|
+
context: RepositoryContext,
|
|
94
|
+
resource: Writable<ProductType>,
|
|
95
|
+
{ attributeName, label }: ProductTypeChangeLabelAction
|
|
96
|
+
) => {
|
|
97
|
+
resource.attributes?.forEach((value) => {
|
|
98
|
+
if (value.name === attributeName) {
|
|
99
|
+
value.label = label
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
addAttributeDefinition: (
|
|
104
|
+
context: RepositoryContext,
|
|
105
|
+
resource: Writable<ProductType>,
|
|
106
|
+
{ attribute }: ProductTypeAddAttributeDefinitionAction
|
|
107
|
+
) => {
|
|
108
|
+
resource.attributes?.push(
|
|
109
|
+
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
changeAttributeOrderByName: (
|
|
113
|
+
context: RepositoryContext,
|
|
114
|
+
resource: Writable<ProductType>,
|
|
115
|
+
{ attributeNames }: ProductTypeChangeAttributeOrderByNameAction
|
|
116
|
+
) => {
|
|
117
|
+
const attrs = new Map(
|
|
118
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
119
|
+
)
|
|
120
|
+
const result: AttributeDefinition[] = []
|
|
121
|
+
let current = resource.attributes
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
attributeNames.forEach((attrName) => {
|
|
124
|
+
const attr = attrs.get(attrName)
|
|
125
|
+
if (attr === undefined) {
|
|
126
|
+
throw new Error('New attr')
|
|
127
|
+
}
|
|
128
|
+
result.push(attr)
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
// Remove from current items
|
|
131
|
+
current = current?.filter((f) => f.name !== attrName)
|
|
132
|
+
})
|
|
133
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
|
-
|
|
134
|
+
resource.attributes = result
|
|
135
|
+
// Add attrs which were not specified in the order as last items. Not
|
|
136
|
+
// sure if this follows commercetools
|
|
137
|
+
if (current) {
|
|
138
|
+
resource.attributes.push(...current)
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
removeAttributeDefinition: (
|
|
142
|
+
context: RepositoryContext,
|
|
143
|
+
resource: Writable<ProductType>,
|
|
144
|
+
{ name }: ProductTypeRemoveAttributeDefinitionAction
|
|
145
|
+
) => {
|
|
146
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name)
|
|
147
|
+
},
|
|
148
|
+
removeEnumValues: (
|
|
149
|
+
context: RepositoryContext,
|
|
150
|
+
resource: Writable<ProductType>,
|
|
151
|
+
{ attributeName, keys }: ProductTypeRemoveEnumValuesAction
|
|
152
|
+
) => {
|
|
153
|
+
resource.attributes?.forEach((attr) => {
|
|
154
|
+
if (attr.name == attributeName) {
|
|
155
|
+
if (attr.type.name == 'enum') {
|
|
156
|
+
attr.type.values = attr.type.values.filter(
|
|
157
|
+
(v) => !keys.includes(v.key)
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
161
|
+
if (attr.type.name == 'set') {
|
|
162
|
+
if (attr.type.elementType.name == 'enum') {
|
|
163
|
+
attr.type.elementType.values =
|
|
164
|
+
attr.type.elementType.values.filter(
|
|
165
|
+
(v) => !keys.includes(v.key)
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
173
|
}
|