@labdigital/commercetools-mock 1.3.0 → 1.3.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.global.js +23 -27
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.ts +2 -2
- package/src/lib/projectionSearchFilter.ts +3 -3
- package/src/repositories/cart.ts +5 -10
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* See https://docs.commercetools.com/api/predicates/query
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import Lexer from 'perplex'
|
|
8
8
|
import { ITokenPosition, Parser } from 'pratt'
|
|
9
9
|
import { haversineDistance } from './haversine'
|
|
10
10
|
|
|
@@ -104,7 +104,7 @@ const resolveValue = (obj: any, val: TypeSymbol): any => {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const getLexer = (value: string) =>
|
|
107
|
-
new
|
|
107
|
+
new Lexer<string>(value)
|
|
108
108
|
|
|
109
109
|
.token('AND', /and(?![-_a-z0-9]+)/i)
|
|
110
110
|
.token('OR', /or(?![-_a-z0-9]+)/i)
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
|
|
6
|
-
import
|
|
6
|
+
import Lexer from 'perplex'
|
|
7
7
|
import Parser from 'pratt'
|
|
8
|
-
import type { Writable } from '../types'
|
|
9
8
|
import { nestedLookup } from '../helpers'
|
|
9
|
+
import type { Writable } from '../types'
|
|
10
10
|
|
|
11
11
|
type MatchFunc = (target: any) => boolean
|
|
12
12
|
|
|
@@ -72,7 +72,7 @@ export const parseFilterExpression = (
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const getLexer = (value: string) =>
|
|
75
|
-
new
|
|
75
|
+
new Lexer<string>(value)
|
|
76
76
|
.token('MISSING', /missing(?![-_a-z0-9]+)/i)
|
|
77
77
|
.token('EXISTS', /exists(?![-_a-z0-9]+)/i)
|
|
78
78
|
.token('RANGE', /range(?![-_a-z0-9]+)/i)
|
package/src/repositories/cart.ts
CHANGED
|
@@ -158,12 +158,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
158
158
|
)
|
|
159
159
|
if (alreadyAdded) {
|
|
160
160
|
// increase quantity and update total price
|
|
161
|
-
resource.lineItems.
|
|
161
|
+
resource.lineItems.forEach((x) => {
|
|
162
162
|
if (x.productId === product?.id && x.variant.id === variant?.id) {
|
|
163
163
|
x.quantity += quantity
|
|
164
164
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
165
165
|
}
|
|
166
|
-
return x
|
|
167
166
|
})
|
|
168
167
|
} else {
|
|
169
168
|
// add line item
|
|
@@ -243,20 +242,17 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
243
242
|
})
|
|
244
243
|
}
|
|
245
244
|
|
|
246
|
-
|
|
247
|
-
if (shouldDelete) {
|
|
245
|
+
if (quantity === 0) {
|
|
248
246
|
// delete line item
|
|
249
247
|
resource.lineItems = resource.lineItems.filter(
|
|
250
248
|
(x) => x.id !== lineItemId
|
|
251
249
|
)
|
|
252
250
|
} else {
|
|
253
|
-
|
|
254
|
-
resource.lineItems.map((x) => {
|
|
251
|
+
resource.lineItems.forEach((x) => {
|
|
255
252
|
if (x.id === lineItemId && quantity) {
|
|
256
|
-
x.quantity
|
|
253
|
+
x.quantity = quantity
|
|
257
254
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
258
255
|
}
|
|
259
|
-
return x
|
|
260
256
|
})
|
|
261
257
|
}
|
|
262
258
|
|
|
@@ -285,12 +281,11 @@ export class CartRepository extends AbstractResourceRepository<'cart'> {
|
|
|
285
281
|
)
|
|
286
282
|
} else {
|
|
287
283
|
// decrease quantity and update total price
|
|
288
|
-
resource.lineItems.
|
|
284
|
+
resource.lineItems.forEach((x) => {
|
|
289
285
|
if (x.id === lineItemId && quantity) {
|
|
290
286
|
x.quantity -= quantity
|
|
291
287
|
x.totalPrice.centAmount = calculateLineItemTotalPrice(x)
|
|
292
288
|
}
|
|
293
|
-
return x
|
|
294
289
|
})
|
|
295
290
|
}
|
|
296
291
|
|