Skip to content

Commit

Permalink
gei-users edit user
Browse files Browse the repository at this point in the history
  • Loading branch information
Matnabru committed Aug 4, 2023
1 parent a48ddd5 commit 6abbd38
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 35 deletions.
5 changes: 3 additions & 2 deletions packages/integrations/gei-users/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "gei-users",
"version": "0.7.1",
"version": "0.7.2",
"description": "Automatically generated by graphql-editor-cli",
"main": "lib/index.js",
"scripts": {
"start": "gecli dev",
"build": "tsc",
"watch": "tsc --watch",
"update": "gecli codegen models && gecli schema && gecli codegen typings",
"integrate": "gecli gei integrate"
"integrate": "gecli gei integrate",
"integrate:env": "dotenv -e .env gecli gei integrate"
},
"author": "GraphQL Editor Centaur Generator",
"license": "ISC",
Expand Down
16 changes: 15 additions & 1 deletion packages/integrations/gei-users/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ type Mutation{
): Boolean!
}

enum EditUserError {
USERNAME_ALREADY_TAKEN
FAILED_MONGO_UPDATE
USER_DOES_NOT_EXIST
}

type EditUserResponse{
result: Boolean
hasError: EditUserError
}


enum VerifyEmailError{
TOKEN_CANNOT_BE_FOUND
}
Expand Down Expand Up @@ -240,7 +252,9 @@ input RemoveUserFromTeamInput{
}

input UpdateUserInput{
username: String!
userId: String!
username: String
fullName: String
}

input GenerateOAuthTokenInput{
Expand Down
34 changes: 34 additions & 0 deletions packages/integrations/gei-users/src/Mutation/editUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FieldResolveInput } from 'stucco-js';
import { orm } from '../db/orm.js';
import { EditUserError, resolverFor } from '../zeus/index.js';

export const handler = async (input: FieldResolveInput) =>
resolverFor('Mutation', 'editUser', async ({ updatedUser }) => {
const o = await orm();
const { userId, username, fullName } = updatedUser;
const userCollection = o('UserCollection').collection;

const user = await userCollection.findOne({ userId });
if (!user) {
return { hasError: EditUserError.USER_DOES_NOT_EXIST };
}

if (username !== undefined && username !== null) {
const existingUser = await userCollection.findOne({ username, userId: { $ne: userId } });
if (existingUser) {
return { hasError: EditUserError.USERNAME_ALREADY_TAKEN };
}
}
const update: any = {};
if (username !== undefined && username !== null) {
update.username = username;
}
if (fullName !== undefined && fullName !== null) {
update.fullName = fullName;
}

const res = await userCollection.updateOne({ userId }, { $set: update });
if (res.modifiedCount === 0) {
return { hasError: EditUserError.FAILED_MONGO_UPDATE };
}
})(input.arguments);
6 changes: 6 additions & 0 deletions packages/integrations/gei-users/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { handler as requestForForgotPassword } from './Query/requestForForgotPas
import { handler as createTeam } from './Mutation/createTeam.js';
import { handler as verifyEmail } from './Mutation/verifyEmail.js';
import { handler as changePasswordWhenLogged } from './Mutation/changePasswordWhenLogged.js';
import { handler as editUser} from './Mutation/editUser.js'

import { handler as integrateSocialAccount } from './Mutation/integrateSocialAccount.js';
import { handler as changePasswordWithToken } from './Mutation/changePasswordWithToken.js';
Expand Down Expand Up @@ -106,6 +107,11 @@ export const integration = NewIntegration({
description: 'Provide team name and become the owner of the new team',
handler: createTeam,
},
editUser: {
name: 'EditUser',
description: 'Edit user data',
handler: editUser,
},
verifyEmail: {
name: 'VerifyEmail',
description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ModelTypes } from '../zeus/index.js';

export type EditUserResponseModel = ModelTypes['EditUserResponse'];
2 changes: 2 additions & 0 deletions packages/integrations/gei-users/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QueryModel } from './QueryModel.js'
import { UserMemberModel } from './UserMemberModel.js'
import { MutationModel } from './MutationModel.js'
import { EditUserResponseModel } from './EditUserResponseModel.js'
import { VerifyEmailResponseModel } from './VerifyEmailResponseModel.js'
import { ChangePasswordWhenLoggedResponseModel } from './ChangePasswordWhenLoggedResponseModel.js'
import { ChangePasswordWithTokenResponseModel } from './ChangePasswordWithTokenResponseModel.js'
Expand Down Expand Up @@ -33,6 +34,7 @@ export type Models = {
QueryModel: QueryModel;
UserMemberModel: UserMemberModel;
MutationModel: MutationModel;
EditUserResponseModel: EditUserResponseModel;
VerifyEmailResponseModel: VerifyEmailResponseModel;
ChangePasswordWhenLoggedResponseModel: ChangePasswordWhenLoggedResponseModel;
ChangePasswordWithTokenResponseModel: ChangePasswordWithTokenResponseModel;
Expand Down
5 changes: 5 additions & 0 deletions packages/integrations/gei-users/src/zeus/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const AllTypesProps: Record<string,any> = {
updatedUser:"UpdateUserInput"
}
},
EditUserError: "enum" as const,
VerifyEmailError: "enum" as const,
ChangePasswordWhenLoggedError: "enum" as const,
ChangePasswordWithTokenError: "enum" as const,
Expand Down Expand Up @@ -180,6 +181,10 @@ export const ReturnTypes: Record<string,any> = {
generateOAuthToken:"GenerateOAuthTokenResponse",
editUser:"Boolean"
},
EditUserResponse:{
result:"Boolean",
hasError:"EditUserError"
},
VerifyEmailResponse:{
result:"Boolean",
hasError:"VerifyEmailError"
Expand Down
45 changes: 41 additions & 4 deletions packages/integrations/gei-users/src/zeus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,12 @@ integrateSocialAccount?: [{ userData: ValueTypes["SimpleUserInput"] | Variable<a
generateOAuthToken?: [{ tokenData: ValueTypes["GenerateOAuthTokenInput"] | Variable<any, string>},ValueTypes["GenerateOAuthTokenResponse"]],
editUser?: [{ updatedUser: ValueTypes["UpdateUserInput"] | Variable<any, string>},boolean | `@${string}`],
__typename?: boolean | `@${string}`
}>;
["EditUserError"]:EditUserError;
["EditUserResponse"]: AliasType<{
result?:boolean | `@${string}`,
hasError?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["VerifyEmailError"]:VerifyEmailError;
["VerifyEmailResponse"]: AliasType<{
Expand Down Expand Up @@ -956,7 +962,9 @@ editUser?: [{ updatedUser: ValueTypes["UpdateUserInput"] | Variable<any, string>
teamId: string | Variable<any, string>
};
["UpdateUserInput"]: {
username: string | Variable<any, string>
userId: string | Variable<any, string>,
username?: string | undefined | null | Variable<any, string>,
fullName?: string | undefined | null | Variable<any, string>
};
["GenerateOAuthTokenInput"]: {
social: ValueTypes["SocialKind"] | Variable<any, string>,
Expand Down Expand Up @@ -1173,6 +1181,12 @@ integrateSocialAccount?: [{ userData: ResolverInputTypes["SimpleUserInput"]},Res
generateOAuthToken?: [{ tokenData: ResolverInputTypes["GenerateOAuthTokenInput"]},ResolverInputTypes["GenerateOAuthTokenResponse"]],
editUser?: [{ updatedUser: ResolverInputTypes["UpdateUserInput"]},boolean | `@${string}`],
__typename?: boolean | `@${string}`
}>;
["EditUserError"]:EditUserError;
["EditUserResponse"]: AliasType<{
result?:boolean | `@${string}`,
hasError?:boolean | `@${string}`,
__typename?: boolean | `@${string}`
}>;
["VerifyEmailError"]:VerifyEmailError;
["VerifyEmailResponse"]: AliasType<{
Expand Down Expand Up @@ -1251,7 +1265,9 @@ editUser?: [{ updatedUser: ResolverInputTypes["UpdateUserInput"]},boolean | `@${
teamId: string
};
["UpdateUserInput"]: {
username: string
userId: string,
username?: string | undefined | null,
fullName?: string | undefined | null
};
["GenerateOAuthTokenInput"]: {
social: ResolverInputTypes["SocialKind"],
Expand Down Expand Up @@ -1465,6 +1481,11 @@ export type ModelTypes = {
integrateSocialAccount: ModelTypes["IntegrateSocialAccountResponse"],
generateOAuthToken: ModelTypes["GenerateOAuthTokenResponse"],
editUser: boolean
};
["EditUserError"]:EditUserError;
["EditUserResponse"]: {
result?: boolean | undefined,
hasError?: ModelTypes["EditUserError"] | undefined
};
["VerifyEmailError"]:VerifyEmailError;
["VerifyEmailResponse"]: {
Expand Down Expand Up @@ -1531,7 +1552,9 @@ export type ModelTypes = {
teamId: string
};
["UpdateUserInput"]: {
username: string
userId: string,
username?: string | undefined,
fullName?: string | undefined
};
["GenerateOAuthTokenInput"]: {
social: ModelTypes["SocialKind"],
Expand Down Expand Up @@ -1724,6 +1747,12 @@ export type GraphQLTypes = {
integrateSocialAccount: GraphQLTypes["IntegrateSocialAccountResponse"],
generateOAuthToken: GraphQLTypes["GenerateOAuthTokenResponse"],
editUser: boolean
};
["EditUserError"]: EditUserError;
["EditUserResponse"]: {
__typename: "EditUserResponse",
result?: boolean | undefined,
hasError?: GraphQLTypes["EditUserError"] | undefined
};
["VerifyEmailError"]: VerifyEmailError;
["VerifyEmailResponse"]: {
Expand Down Expand Up @@ -1802,7 +1831,9 @@ export type GraphQLTypes = {
teamId: string
};
["UpdateUserInput"]: {
username: string
userId: string,
username?: string | undefined,
fullName?: string | undefined
};
["GenerateOAuthTokenInput"]: {
social: GraphQLTypes["SocialKind"],
Expand Down Expand Up @@ -1977,6 +2008,11 @@ export const enum MustBeTeamMemberError {
USER_IS_NOT_A_TEAM_MEMBER = "USER_IS_NOT_A_TEAM_MEMBER",
TEAM_DOES_NOT_EXIST = "TEAM_DOES_NOT_EXIST"
}
export const enum EditUserError {
USERNAME_ALREADY_TAKEN = "USERNAME_ALREADY_TAKEN",
FAILED_MONGO_UPDATE = "FAILED_MONGO_UPDATE",
USER_DOES_NOT_EXIST = "USER_DOES_NOT_EXIST"
}
export const enum VerifyEmailError {
TOKEN_CANNOT_BE_FOUND = "TOKEN_CANNOT_BE_FOUND"
}
Expand Down Expand Up @@ -2070,6 +2106,7 @@ export const enum ProviderErrors {
type ZEUS_VARIABLES = {
["MustBeTeamMemberError"]: ValueTypes["MustBeTeamMemberError"];
["GetOAuthInput"]: ValueTypes["GetOAuthInput"];
["EditUserError"]: ValueTypes["EditUserError"];
["VerifyEmailError"]: ValueTypes["VerifyEmailError"];
["ChangePasswordWhenLoggedError"]: ValueTypes["ChangePasswordWhenLoggedError"];
["ChangePasswordWithTokenError"]: ValueTypes["ChangePasswordWithTokenError"];
Expand Down
Loading

0 comments on commit 6abbd38

Please sign in to comment.