@kontakta/cloud-code-directives
Advanced tools
+1
-1
| { | ||
| "name": "@kontakta/cloud-code-directives", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
@@ -51,3 +51,3 @@ import rename from 'deep-rename-keys'; | ||
| export async function fetchFullProduct(productId: string, variantId: string, originObject: any) { | ||
| export async function fetchFullProduct(productId: string, variantId: string | null, originObject: any) { | ||
| try { | ||
@@ -58,3 +58,3 @@ let result; | ||
| const prod = await new Parse.Query('Product') | ||
| .include(['store', 'images']) | ||
| .include(['categories', 'catalog']) | ||
| .equalTo('objectId', productId) | ||
@@ -66,3 +66,3 @@ .first({ useMasterKey: true }); | ||
| const product = await new Parse.Query('Product') | ||
| .include('store') | ||
| .include(['categories', 'catalog']) | ||
| .equalTo('objectId', productId) | ||
@@ -74,3 +74,3 @@ .first({ useMasterKey: true }); | ||
| return result ? { ...originObject, ...result } : null; | ||
| return result ? { ...result, ...originObject, orderQuantity: originObject.quantity } : null; | ||
| } catch (error) { | ||
@@ -77,0 +77,0 @@ // TODO: report |
@@ -8,3 +8,3 @@ import { defaultFieldResolver, GraphQLFieldConfig } from 'graphql'; | ||
| unknown, | ||
| { productKey: string; variantKey: string } | ||
| { id: string; parentId: string } | ||
| > | ||
@@ -21,4 +21,2 @@ ) { | ||
| const { productKey, variantKey } = params[1]; | ||
| if (!result) return result; | ||
@@ -30,5 +28,8 @@ | ||
| const promises = result.map((r) => | ||
| fetchFullProduct(r[productKey] as string, r[variantKey] as string, r) | ||
| ); | ||
| const promises = result.map((r) => { | ||
| const variantId = !r.parentId || r.parentId === 'root' ? null : r.id as string; | ||
| const productId = !r.parentId || r.parentId === 'root' ? r.id as string : r.parentId as string; | ||
| return fetchFullProduct(productId, variantId, r); | ||
| }); | ||
| const fetched = await Promise.all(promises); | ||
@@ -35,0 +36,0 @@ return fetched.filter((f) => !!f); |
12483
1.46%342
0.29%