Skip to content

Commit 7cfa1cd

Browse files
committed
addFieldsToCrudCreate
1 parent a375009 commit 7cfa1cd

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

packages/integrations/gei-crud/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gei-crud",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"description": "GraphQL Editor integration for stucco. Allows basic crud operations and relations.",
55
"main": "lib/index.js",
66
"private": false,

packages/integrations/gei-crud/src/Mutation/create.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ObjectId, OptionalId } from 'mongodb';
22
import { FieldResolveInput } from 'stucco-js';
3-
import { prepareModel, prepareSourceParameters } from '../data.js';
3+
import { createObjectFromAddFields, prepareModel, prepareSourceParameters } from '../data.js';
44
import { DB } from '../db/orm.js';
55
import { DataInput } from '../integration.js';
66
import { getReturnTypeName } from '../shared.js';
@@ -29,14 +29,5 @@ export const create = async (input: FieldResolveInput & Partial<DataInput>) =>
2929
.then((result) => result.insertedId);
3030
});
3131

32-
function createObjectFromAddFields(addFieldsArray: { name: string; value: unknown }[]) {
33-
const result: { [key: string]: unknown } = {};
3432

35-
for (const field of addFieldsArray) {
36-
const { name, value } = field;
37-
result[name] = value;
38-
}
39-
40-
return result;
41-
}
4233
export default create;

packages/integrations/gei-crud/src/Mutation/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FieldResolveInput } from 'stucco-js';
2-
import { prepareModel, prepare_id, prepareSourceParameters } from '../data.js';
2+
import { prepareModel, prepare_id, prepareSourceParameters, createObjectFromAddFields } from '../data.js';
33
import { DB } from '../db/orm.js';
44
import { DataInput } from '../integration.js';
55

@@ -34,7 +34,7 @@ export const update = async (input: FieldResolveInput & Partial<DataInput>) =>
3434
console.log(setter);
3535
const filterInput: Record<string, any> = { _id, ...prepareSourceParameters(input) };
3636
const res = await db(input.data?.model || prepareModel(input)).collection.updateOne(filterInput, {
37-
$set: { ...setter, updatedAt: new Date().toISOString() },
37+
$set: { ...setter, ...(input.data?.addFields && createObjectFromAddFields(input.data.addFields)), updatedAt: new Date().toISOString() },
3838
});
3939
if (res.matchedCount < 1)
4040
throw new Error(`Object for update not found. Please check parameters: ${JSON.stringify(filterInput)}`);

packages/integrations/gei-crud/src/data.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,16 @@ export const prepareRequired_id = (input: FieldResolveInput) => {
8181
}
8282
return _id as string;
8383
};
84+
85+
86+
87+
export function createObjectFromAddFields(addFieldsArray: { name: string; value: unknown }[]) {
88+
const result: { [key: string]: unknown } = {};
89+
90+
for (const field of addFieldsArray) {
91+
const { name, value } = field;
92+
result[name] = value;
93+
}
94+
95+
return result;
96+
}

packages/integrations/gei-users/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gei-users",
3-
"version": "0.8.1",
3+
"version": "0.8.2",
44
"description": "Automatically generated by graphql-editor-cli",
55
"main": "lib/index.js",
66
"scripts": {

packages/integrations/gei-users/src/Mutation/sendInvitationToTeam.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const sendInvitationToTeam = async (input: FieldResolveInput) =>
2323
if (!teamById) return { hasError: SendInvitationToTeamError.USER_IS_NOT_OWNER_OF_THE_TEAM };
2424
const recipientUser = await o(UserCollection).collection.find({ username }).toArray();
2525
if (recipientUser.length === 0) return { hasError: SendInvitationToTeamError.CANNOT_FIND_USER };
26-
if (recipientUser.length >= 2) return { hasError: SendInvitationToTeamError.USERNAME_IS_TOO_AMBIGUOUS };
26+
if (recipientUser.length > 2) return { hasError: SendInvitationToTeamError.USERNAME_IS_TOO_AMBIGUOUS };
2727

2828
if (teamById.members.includes(recipientUser[0]._id))
29-
return { hasError: SendInvitationToTeamError.USER_ALREADY_HAS_YOUR_INVITATION };
29+
return { hasError: SendInvitationToTeamError.USER_ALREADY_EXISTS_IN_THE_TEAM };
3030
const result = await o(TeamInvitationsCollection).createWithAutoFields('_id')({
3131
teamId: teamById._id,
3232
teamName: teamById.name,

0 commit comments

Comments
 (0)