Skip to content

Commit

Permalink
fixForUpdateWithArray
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbrui committed Sep 8, 2023
1 parent 7608825 commit bf3faea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 0 additions & 3 deletions packages/integrations/gei-crud/src/Mutation/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
const relatedCollections = relatedCollectionsField.replace(/["' ]/g, '').split(',');
const prepareFields = prepareRelatedField(input)?.replace(/[{ }]/g, '').split(',');
Expand Down
9 changes: 7 additions & 2 deletions packages/integrations/gei-crud/src/Mutation/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<string, any> = { _id, ...prepareSourceParameters(input) };
const res = await db(prepareModel(input)).collection.updateOne(filterInput, {
$set: { ...setter, updatedAt: new Date().toISOString() },
Expand Down

0 comments on commit bf3faea

Please sign in to comment.