@labdigital/commercetools-mock 1.5.0 → 1.6.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.
Files changed (129) hide show
  1. package/README.md +5 -4
  2. package/dist/index.cjs +117 -17
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.js +117 -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 +135 -50
  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 +502 -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,236 +1,236 @@
1
1
  import type {
2
- ShippingMethod,
3
- ShippingMethodAddShippingRateAction,
4
- ShippingMethodAddZoneAction,
5
- ShippingMethodChangeIsDefaultAction,
6
- ShippingMethodChangeNameAction,
7
- ShippingMethodDraft,
8
- ShippingMethodRemoveZoneAction,
9
- ShippingMethodSetCustomFieldAction,
10
- ShippingMethodSetCustomTypeAction,
11
- ShippingMethodSetDescriptionAction,
12
- ShippingMethodSetKeyAction,
13
- ShippingMethodSetLocalizedDescriptionAction,
14
- ShippingMethodSetLocalizedNameAction,
15
- ShippingMethodSetPredicateAction,
16
- ShippingMethodUpdateAction,
17
- ShippingRate,
18
- ShippingRateDraft,
19
- ZoneRate,
20
- ZoneRateDraft,
21
- ZoneReference,
2
+ ShippingMethod,
3
+ ShippingMethodAddShippingRateAction,
4
+ ShippingMethodAddZoneAction,
5
+ ShippingMethodChangeIsDefaultAction,
6
+ ShippingMethodChangeNameAction,
7
+ ShippingMethodDraft,
8
+ ShippingMethodRemoveZoneAction,
9
+ ShippingMethodSetCustomFieldAction,
10
+ ShippingMethodSetCustomTypeAction,
11
+ ShippingMethodSetDescriptionAction,
12
+ ShippingMethodSetKeyAction,
13
+ ShippingMethodSetLocalizedDescriptionAction,
14
+ ShippingMethodSetLocalizedNameAction,
15
+ ShippingMethodSetPredicateAction,
16
+ ShippingMethodUpdateAction,
17
+ ShippingRate,
18
+ ShippingRateDraft,
19
+ ZoneRate,
20
+ ZoneRateDraft,
21
+ ZoneReference,
22
22
  } from '@commercetools/platform-sdk'
23
23
  import deepEqual from 'deep-equal'
24
24
  import { getBaseResourceProperties } from '../helpers.js'
25
25
  import type { Writable } from '../types.js'
26
26
  import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
27
27
  import {
28
- createCustomFields,
29
- createTypedMoney,
30
- getReferenceFromResourceIdentifier,
28
+ createCustomFields,
29
+ createTypedMoney,
30
+ getReferenceFromResourceIdentifier,
31
31
  } from './helpers.js'
32
32
 
33
33
  export class ShippingMethodRepository extends AbstractResourceRepository<'shipping-method'> {
34
- getTypeId() {
35
- return 'shipping-method' as const
36
- }
34
+ getTypeId() {
35
+ return 'shipping-method' as const
36
+ }
37
37
 
38
- create(
39
- context: RepositoryContext,
40
- draft: ShippingMethodDraft
41
- ): ShippingMethod {
42
- const resource: ShippingMethod = {
43
- ...getBaseResourceProperties(),
44
- ...draft,
45
- taxCategory: getReferenceFromResourceIdentifier(
46
- draft.taxCategory,
47
- context.projectKey,
48
- this._storage
49
- ),
50
- zoneRates: draft.zoneRates?.map((z) =>
51
- this._transformZoneRateDraft(context, z)
52
- ),
53
- custom: createCustomFields(
54
- draft.custom,
55
- context.projectKey,
56
- this._storage
57
- ),
58
- }
59
- this.saveNew(context, resource)
60
- return resource
61
- }
38
+ create(
39
+ context: RepositoryContext,
40
+ draft: ShippingMethodDraft
41
+ ): ShippingMethod {
42
+ const resource: ShippingMethod = {
43
+ ...getBaseResourceProperties(),
44
+ ...draft,
45
+ taxCategory: getReferenceFromResourceIdentifier(
46
+ draft.taxCategory,
47
+ context.projectKey,
48
+ this._storage
49
+ ),
50
+ zoneRates: draft.zoneRates?.map((z) =>
51
+ this._transformZoneRateDraft(context, z)
52
+ ),
53
+ custom: createCustomFields(
54
+ draft.custom,
55
+ context.projectKey,
56
+ this._storage
57
+ ),
58
+ }
59
+ this.saveNew(context, resource)
60
+ return resource
61
+ }
62
62
 
63
- private _transformZoneRateDraft = (
64
- context: RepositoryContext,
65
- draft: ZoneRateDraft
66
- ): ZoneRate => ({
67
- ...draft,
68
- zone: getReferenceFromResourceIdentifier<ZoneReference>(
69
- draft.zone,
70
- context.projectKey,
71
- this._storage
72
- ),
73
- shippingRates: draft.shippingRates?.map(this._transformShippingRate),
74
- })
63
+ private _transformZoneRateDraft = (
64
+ context: RepositoryContext,
65
+ draft: ZoneRateDraft
66
+ ): ZoneRate => ({
67
+ ...draft,
68
+ zone: getReferenceFromResourceIdentifier<ZoneReference>(
69
+ draft.zone,
70
+ context.projectKey,
71
+ this._storage
72
+ ),
73
+ shippingRates: draft.shippingRates?.map(this._transformShippingRate),
74
+ })
75
75
 
76
- private _transformShippingRate = (rate: ShippingRateDraft): ShippingRate => ({
77
- price: createTypedMoney(rate.price),
78
- freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
79
- tiers: rate.tiers || [],
80
- })
76
+ private _transformShippingRate = (rate: ShippingRateDraft): ShippingRate => ({
77
+ price: createTypedMoney(rate.price),
78
+ freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
79
+ tiers: rate.tiers || [],
80
+ })
81
81
 
82
- actions: Partial<
83
- Record<
84
- ShippingMethodUpdateAction['action'],
85
- (
86
- context: RepositoryContext,
87
- resource: Writable<ShippingMethod>,
88
- action: any
89
- ) => void
90
- >
91
- > = {
92
- addShippingRate: (
93
- _context: RepositoryContext,
94
- resource: Writable<ShippingMethod>,
95
- { shippingRate, zone }: ShippingMethodAddShippingRateAction
96
- ) => {
97
- const rate = this._transformShippingRate(shippingRate)
82
+ actions: Partial<
83
+ Record<
84
+ ShippingMethodUpdateAction['action'],
85
+ (
86
+ context: RepositoryContext,
87
+ resource: Writable<ShippingMethod>,
88
+ action: any
89
+ ) => void
90
+ >
91
+ > = {
92
+ addShippingRate: (
93
+ _context: RepositoryContext,
94
+ resource: Writable<ShippingMethod>,
95
+ { shippingRate, zone }: ShippingMethodAddShippingRateAction
96
+ ) => {
97
+ const rate = this._transformShippingRate(shippingRate)
98
98
 
99
- resource.zoneRates.forEach((zoneRate) => {
100
- if (zoneRate.zone.id === zone.id) {
101
- zoneRate.shippingRates.push(rate)
102
- return
103
- }
104
- })
105
- resource.zoneRates.push({
106
- zone: {
107
- typeId: 'zone',
108
- id: zone.id!,
109
- },
110
- shippingRates: [rate],
111
- })
112
- },
113
- removeShippingRate: (
114
- _context: RepositoryContext,
115
- resource: Writable<ShippingMethod>,
116
- { shippingRate, zone }: ShippingMethodAddShippingRateAction
117
- ) => {
118
- const rate = this._transformShippingRate(shippingRate)
99
+ resource.zoneRates.forEach((zoneRate) => {
100
+ if (zoneRate.zone.id === zone.id) {
101
+ zoneRate.shippingRates.push(rate)
102
+ return
103
+ }
104
+ })
105
+ resource.zoneRates.push({
106
+ zone: {
107
+ typeId: 'zone',
108
+ id: zone.id!,
109
+ },
110
+ shippingRates: [rate],
111
+ })
112
+ },
113
+ removeShippingRate: (
114
+ _context: RepositoryContext,
115
+ resource: Writable<ShippingMethod>,
116
+ { shippingRate, zone }: ShippingMethodAddShippingRateAction
117
+ ) => {
118
+ const rate = this._transformShippingRate(shippingRate)
119
119
 
120
- resource.zoneRates.forEach((zoneRate) => {
121
- if (zoneRate.zone.id === zone.id) {
122
- zoneRate.shippingRates = zoneRate.shippingRates.filter(
123
- (otherRate) => !deepEqual(rate, otherRate)
124
- )
125
- }
126
- })
127
- },
128
- addZone: (
129
- context: RepositoryContext,
130
- resource: Writable<ShippingMethod>,
131
- { zone }: ShippingMethodAddZoneAction
132
- ) => {
133
- const zoneReference = getReferenceFromResourceIdentifier<ZoneReference>(
134
- zone,
135
- context.projectKey,
136
- this._storage
137
- )
120
+ resource.zoneRates.forEach((zoneRate) => {
121
+ if (zoneRate.zone.id === zone.id) {
122
+ zoneRate.shippingRates = zoneRate.shippingRates.filter(
123
+ (otherRate) => !deepEqual(rate, otherRate)
124
+ )
125
+ }
126
+ })
127
+ },
128
+ addZone: (
129
+ context: RepositoryContext,
130
+ resource: Writable<ShippingMethod>,
131
+ { zone }: ShippingMethodAddZoneAction
132
+ ) => {
133
+ const zoneReference = getReferenceFromResourceIdentifier<ZoneReference>(
134
+ zone,
135
+ context.projectKey,
136
+ this._storage
137
+ )
138
138
 
139
- if (resource.zoneRates === undefined) {
140
- resource.zoneRates = []
141
- }
139
+ if (resource.zoneRates === undefined) {
140
+ resource.zoneRates = []
141
+ }
142
142
 
143
- resource.zoneRates.push({
144
- zone: zoneReference,
145
- shippingRates: [],
146
- })
147
- },
148
- removeZone: (
149
- _context: RepositoryContext,
150
- resource: Writable<ShippingMethod>,
151
- { zone }: ShippingMethodRemoveZoneAction
152
- ) => {
153
- resource.zoneRates = resource.zoneRates.filter(
154
- (zoneRate) => zoneRate.zone.id !== zone.id
155
- )
156
- },
157
- setKey: (
158
- _context: RepositoryContext,
159
- resource: Writable<ShippingMethod>,
160
- { key }: ShippingMethodSetKeyAction
161
- ) => {
162
- resource.key = key
163
- },
164
- setDescription: (
165
- _context: RepositoryContext,
166
- resource: Writable<ShippingMethod>,
167
- { description }: ShippingMethodSetDescriptionAction
168
- ) => {
169
- resource.description = description
170
- },
171
- setLocalizedDescription: (
172
- _context: RepositoryContext,
173
- resource: Writable<ShippingMethod>,
174
- { localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
175
- ) => {
176
- resource.localizedDescription = localizedDescription
177
- },
178
- setLocalizedName: (
179
- _context: RepositoryContext,
180
- resource: Writable<ShippingMethod>,
181
- { localizedName }: ShippingMethodSetLocalizedNameAction
182
- ) => {
183
- resource.localizedName = localizedName
184
- },
185
- setPredicate: (
186
- _context: RepositoryContext,
187
- resource: Writable<ShippingMethod>,
188
- { predicate }: ShippingMethodSetPredicateAction
189
- ) => {
190
- resource.predicate = predicate
191
- },
192
- changeIsDefault: (
193
- _context: RepositoryContext,
194
- resource: Writable<ShippingMethod>,
195
- { isDefault }: ShippingMethodChangeIsDefaultAction
196
- ) => {
197
- resource.isDefault = isDefault
198
- },
199
- changeName: (
200
- _context: RepositoryContext,
201
- resource: Writable<ShippingMethod>,
202
- { name }: ShippingMethodChangeNameAction
203
- ) => {
204
- resource.name = name
205
- },
206
- setCustomType: (
207
- context: RepositoryContext,
208
- resource: Writable<ShippingMethod>,
209
- { type, fields }: ShippingMethodSetCustomTypeAction
210
- ) => {
211
- if (type) {
212
- resource.custom = createCustomFields(
213
- { type, fields },
214
- context.projectKey,
215
- this._storage
216
- )
217
- } else {
218
- resource.custom = undefined
219
- }
220
- },
221
- setCustomField: (
222
- context: RepositoryContext,
223
- resource: Writable<ShippingMethod>,
224
- { name, value }: ShippingMethodSetCustomFieldAction
225
- ) => {
226
- if (!resource.custom) {
227
- return
228
- }
229
- if (value === null) {
230
- delete resource.custom.fields[name]
231
- } else {
232
- resource.custom.fields[name] = value
233
- }
234
- },
235
- }
143
+ resource.zoneRates.push({
144
+ zone: zoneReference,
145
+ shippingRates: [],
146
+ })
147
+ },
148
+ removeZone: (
149
+ _context: RepositoryContext,
150
+ resource: Writable<ShippingMethod>,
151
+ { zone }: ShippingMethodRemoveZoneAction
152
+ ) => {
153
+ resource.zoneRates = resource.zoneRates.filter(
154
+ (zoneRate) => zoneRate.zone.id !== zone.id
155
+ )
156
+ },
157
+ setKey: (
158
+ _context: RepositoryContext,
159
+ resource: Writable<ShippingMethod>,
160
+ { key }: ShippingMethodSetKeyAction
161
+ ) => {
162
+ resource.key = key
163
+ },
164
+ setDescription: (
165
+ _context: RepositoryContext,
166
+ resource: Writable<ShippingMethod>,
167
+ { description }: ShippingMethodSetDescriptionAction
168
+ ) => {
169
+ resource.description = description
170
+ },
171
+ setLocalizedDescription: (
172
+ _context: RepositoryContext,
173
+ resource: Writable<ShippingMethod>,
174
+ { localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
175
+ ) => {
176
+ resource.localizedDescription = localizedDescription
177
+ },
178
+ setLocalizedName: (
179
+ _context: RepositoryContext,
180
+ resource: Writable<ShippingMethod>,
181
+ { localizedName }: ShippingMethodSetLocalizedNameAction
182
+ ) => {
183
+ resource.localizedName = localizedName
184
+ },
185
+ setPredicate: (
186
+ _context: RepositoryContext,
187
+ resource: Writable<ShippingMethod>,
188
+ { predicate }: ShippingMethodSetPredicateAction
189
+ ) => {
190
+ resource.predicate = predicate
191
+ },
192
+ changeIsDefault: (
193
+ _context: RepositoryContext,
194
+ resource: Writable<ShippingMethod>,
195
+ { isDefault }: ShippingMethodChangeIsDefaultAction
196
+ ) => {
197
+ resource.isDefault = isDefault
198
+ },
199
+ changeName: (
200
+ _context: RepositoryContext,
201
+ resource: Writable<ShippingMethod>,
202
+ { name }: ShippingMethodChangeNameAction
203
+ ) => {
204
+ resource.name = name
205
+ },
206
+ setCustomType: (
207
+ context: RepositoryContext,
208
+ resource: Writable<ShippingMethod>,
209
+ { type, fields }: ShippingMethodSetCustomTypeAction
210
+ ) => {
211
+ if (type) {
212
+ resource.custom = createCustomFields(
213
+ { type, fields },
214
+ context.projectKey,
215
+ this._storage
216
+ )
217
+ } else {
218
+ resource.custom = undefined
219
+ }
220
+ },
221
+ setCustomField: (
222
+ context: RepositoryContext,
223
+ resource: Writable<ShippingMethod>,
224
+ { name, value }: ShippingMethodSetCustomFieldAction
225
+ ) => {
226
+ if (!resource.custom) {
227
+ return
228
+ }
229
+ if (value === null) {
230
+ delete resource.custom.fields[name]
231
+ } else {
232
+ resource.custom.fields[name] = value
233
+ }
234
+ },
235
+ }
236
236
  }
@@ -1,60 +1,60 @@
1
1
  import type {
2
- CustomerReference,
3
- ShoppingList,
4
- ShoppingListDraft,
2
+ CustomerReference,
3
+ ShoppingList,
4
+ ShoppingListDraft,
5
5
  } from '@commercetools/platform-sdk'
6
6
  import { getBaseResourceProperties } from '../helpers.js'
7
7
  import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
8
8
  import {
9
- createCustomFields,
10
- getReferenceFromResourceIdentifier,
11
- getStoreKeyReference,
9
+ createCustomFields,
10
+ getReferenceFromResourceIdentifier,
11
+ getStoreKeyReference,
12
12
  } from './helpers.js'
13
13
 
14
14
  export class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
15
- getTypeId() {
16
- return 'shopping-list' as const
17
- }
15
+ getTypeId() {
16
+ return 'shopping-list' as const
17
+ }
18
18
 
19
- create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
20
- // const product =
19
+ create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
20
+ // const product =
21
21
 
22
- const resource: ShoppingList = {
23
- ...getBaseResourceProperties(),
24
- ...draft,
25
- custom: createCustomFields(
26
- draft.custom,
27
- context.projectKey,
28
- this._storage
29
- ),
30
- textLineItems: [],
31
- lineItems:
32
- draft.lineItems?.map((e) => ({
33
- ...getBaseResourceProperties(),
34
- ...e,
35
- addedAt: e.addedAt ?? '',
36
- productId: e.productId ?? '',
37
- name: {},
38
- quantity: e.quantity ?? 1,
39
- productType: { typeId: 'product-type', id: '' },
40
- custom: createCustomFields(
41
- e.custom,
42
- context.projectKey,
43
- this._storage
44
- ),
45
- })) ?? [],
46
- customer: draft.customer
47
- ? getReferenceFromResourceIdentifier<CustomerReference>(
48
- draft.customer,
49
- context.projectKey,
50
- this._storage
51
- )
52
- : undefined,
53
- store: draft.store
54
- ? getStoreKeyReference(draft.store, context.projectKey, this._storage)
55
- : undefined,
56
- }
57
- this.saveNew(context, resource)
58
- return resource
59
- }
22
+ const resource: ShoppingList = {
23
+ ...getBaseResourceProperties(),
24
+ ...draft,
25
+ custom: createCustomFields(
26
+ draft.custom,
27
+ context.projectKey,
28
+ this._storage
29
+ ),
30
+ textLineItems: [],
31
+ lineItems:
32
+ draft.lineItems?.map((e) => ({
33
+ ...getBaseResourceProperties(),
34
+ ...e,
35
+ addedAt: e.addedAt ?? '',
36
+ productId: e.productId ?? '',
37
+ name: {},
38
+ quantity: e.quantity ?? 1,
39
+ productType: { typeId: 'product-type', id: '' },
40
+ custom: createCustomFields(
41
+ e.custom,
42
+ context.projectKey,
43
+ this._storage
44
+ ),
45
+ })) ?? [],
46
+ customer: draft.customer
47
+ ? getReferenceFromResourceIdentifier<CustomerReference>(
48
+ draft.customer,
49
+ context.projectKey,
50
+ this._storage
51
+ )
52
+ : undefined,
53
+ store: draft.store
54
+ ? getStoreKeyReference(draft.store, context.projectKey, this._storage)
55
+ : undefined,
56
+ }
57
+ this.saveNew(context, resource)
58
+ return resource
59
+ }
60
60
  }
@@ -1,29 +1,29 @@
1
1
  import type {
2
- Quote,
3
- StagedQuote,
4
- StagedQuoteDraft,
5
- StagedQuoteUpdateAction,
2
+ Quote,
3
+ StagedQuote,
4
+ StagedQuoteDraft,
5
+ StagedQuoteUpdateAction,
6
6
  } from '@commercetools/platform-sdk'
7
7
  import type { Writable } from '../types.js'
8
8
  import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
9
9
 
10
10
  export class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
11
- getTypeId() {
12
- return 'staged-quote' as const
13
- }
11
+ getTypeId() {
12
+ return 'staged-quote' as const
13
+ }
14
14
 
15
- create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote {
16
- throw new Error('not implemented')
17
- }
15
+ create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote {
16
+ throw new Error('not implemented')
17
+ }
18
18
 
19
- actions: Partial<
20
- Record<
21
- StagedQuoteUpdateAction['action'],
22
- (
23
- context: RepositoryContext,
24
- resource: Writable<Quote>,
25
- action: any
26
- ) => void
27
- >
28
- > = {}
19
+ actions: Partial<
20
+ Record<
21
+ StagedQuoteUpdateAction['action'],
22
+ (
23
+ context: RepositoryContext,
24
+ resource: Writable<Quote>,
25
+ action: any
26
+ ) => void
27
+ >
28
+ > = {}
29
29
  }