From bf3faeabe10dcda98f126e0deb69c832827d50c6 Mon Sep 17 00:00:00 2001 From: Pavel Brui Date: Fri, 8 Sep 2023 11:09:26 +0200 Subject: [PATCH] fixForUpdateWithArray --- packages/integrations/gei-crud/src/Mutation/delete.ts | 3 --- packages/integrations/gei-crud/src/Mutation/update.ts | 9 +++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/integrations/gei-crud/src/Mutation/delete.ts b/packages/integrations/gei-crud/src/Mutation/delete.ts index 8e0e8d0..d78fb8c 100644 --- a/packages/integrations/gei-crud/src/Mutation/delete.ts +++ b/packages/integrations/gei-crud/src/Mutation/delete.ts @@ -23,11 +23,8 @@ export const handler = async (input: FieldResolveInput) => { const { data } = getResolverData<{ relatedModel: string }>(input); const relatedCollectionsField = data?.relatedModel?.value; - console.log(relatedCollectionsField?.length); - console.log(relatedCollectionsField); if (relatedCollectionsField && relatedCollectionsField?.length > 2) { - console.log('kkdlckm'); const s = object as Record; const relatedCollections = relatedCollectionsField.replace(/["' ]/g, '').split(','); const prepareFields = prepareRelatedField(input)?.replace(/[{ }]/g, '').split(','); diff --git a/packages/integrations/gei-crud/src/Mutation/update.ts b/packages/integrations/gei-crud/src/Mutation/update.ts index 9328282..b83871a 100644 --- a/packages/integrations/gei-crud/src/Mutation/update.ts +++ b/packages/integrations/gei-crud/src/Mutation/update.ts @@ -14,7 +14,7 @@ export const handler = async (input: FieldResolveInput) => throw new Error(`You need update input argument for this resolver to work`); } - if (typeof entriesWithOutId[0][1] === 'object') { + if (typeof entriesWithOutId[0][1] === 'object' && !Array.isArray(entriesWithOutId[0][1])) { if (entriesWithOutId[1]) throw new Error( 'There should be only string arguments or _id argument and one argument of "input" type to update this model', @@ -25,7 +25,12 @@ export const handler = async (input: FieldResolveInput) => reconstructedObject[key] = value; }); } - const setter = typeof entriesWithOutId[0][1] === 'object' ? entriesWithOutId[0][1] : reconstructedObject; + + const setter = + typeof entriesWithOutId[0][1] === 'object' && !Array.isArray(entriesWithOutId[0][1]) + ? entriesWithOutId[0][1] + : reconstructedObject; + console.log(setter); const filterInput: Record = { _id, ...prepareSourceParameters(input) }; const res = await db(prepareModel(input)).collection.updateOne(filterInput, { $set: { ...setter, updatedAt: new Date().toISOString() },