chore: remove redundant create user mutation
This commit is contained in:
@@ -7,12 +7,10 @@ import generateAuthUrl from './mutations/generate-auth-url.js';
|
|||||||
import createConnection from './mutations/create-connection.js';
|
import createConnection from './mutations/create-connection.js';
|
||||||
import resetConnection from './mutations/reset-connection.js';
|
import resetConnection from './mutations/reset-connection.js';
|
||||||
import updateConnection from './mutations/update-connection.js';
|
import updateConnection from './mutations/update-connection.js';
|
||||||
import createUser from './mutations/create-user.ee.js';
|
|
||||||
import updateFlowStatus from './mutations/update-flow-status.js';
|
import updateFlowStatus from './mutations/update-flow-status.js';
|
||||||
|
|
||||||
const mutationResolvers = {
|
const mutationResolvers = {
|
||||||
createConnection,
|
createConnection,
|
||||||
createUser,
|
|
||||||
executeFlow,
|
executeFlow,
|
||||||
generateAuthUrl,
|
generateAuthUrl,
|
||||||
resetConnection,
|
resetConnection,
|
||||||
|
@@ -1,66 +0,0 @@
|
|||||||
import appConfig from '../../config/app.js';
|
|
||||||
import User from '../../models/user.js';
|
|
||||||
import Role from '../../models/role.js';
|
|
||||||
import emailQueue from '../../queues/email.js';
|
|
||||||
import {
|
|
||||||
REMOVE_AFTER_30_DAYS_OR_150_JOBS,
|
|
||||||
REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
|
||||||
} from '../../helpers/remove-job-configuration.js';
|
|
||||||
|
|
||||||
const createUser = async (_parent, params, context) => {
|
|
||||||
context.currentUser.can('create', 'User');
|
|
||||||
|
|
||||||
const { fullName, email } = params.input;
|
|
||||||
|
|
||||||
const existingUser = await User.query().findOne({
|
|
||||||
email: email.toLowerCase(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingUser) {
|
|
||||||
throw new Error('User already exists!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const userPayload = {
|
|
||||||
fullName,
|
|
||||||
email,
|
|
||||||
status: 'invited',
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
context.currentUser.can('update', 'Role');
|
|
||||||
|
|
||||||
userPayload.roleId = params.input.role.id;
|
|
||||||
} catch {
|
|
||||||
// void
|
|
||||||
const role = await Role.findAdmin();
|
|
||||||
userPayload.roleId = role.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = await User.query().insert(userPayload);
|
|
||||||
|
|
||||||
await user.generateInvitationToken();
|
|
||||||
|
|
||||||
const jobName = `Invitation Email - ${user.id}`;
|
|
||||||
const acceptInvitationUrl = `${appConfig.webAppUrl}/accept-invitation?token=${user.invitationToken}`;
|
|
||||||
|
|
||||||
const jobPayload = {
|
|
||||||
email: user.email,
|
|
||||||
subject: 'You are invited!',
|
|
||||||
template: 'invitation-instructions',
|
|
||||||
params: {
|
|
||||||
fullName: user.fullName,
|
|
||||||
acceptInvitationUrl,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const jobOptions = {
|
|
||||||
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
|
||||||
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
|
|
||||||
};
|
|
||||||
|
|
||||||
await emailQueue.add(jobName, jobPayload, jobOptions);
|
|
||||||
|
|
||||||
return { user, acceptInvitationUrl };
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createUser;
|
|
@@ -3,7 +3,14 @@ type Query {
|
|||||||
}
|
}
|
||||||
type Mutation {
|
type Mutation {
|
||||||
createConnection(input: CreateConnectionInput): Connection
|
createConnection(input: CreateConnectionInput): Connection
|
||||||
|
<<<<<<< HEAD
|
||||||
createUser(input: CreateUserInput): UserWithAcceptInvitationUrl
|
createUser(input: CreateUserInput): UserWithAcceptInvitationUrl
|
||||||
|
=======
|
||||||
|
createFlow(input: CreateFlowInput): Flow
|
||||||
|
deleteCurrentUser: Boolean
|
||||||
|
deleteFlow(input: DeleteFlowInput): Boolean
|
||||||
|
deleteStep(input: DeleteStepInput): Step
|
||||||
|
>>>>>>> 3aa20fed (chore: remove redundant create user mutation)
|
||||||
executeFlow(input: ExecuteFlowInput): executeFlowType
|
executeFlow(input: ExecuteFlowInput): executeFlowType
|
||||||
generateAuthUrl(input: GenerateAuthUrlInput): AuthLink
|
generateAuthUrl(input: GenerateAuthUrlInput): AuthLink
|
||||||
resetConnection(input: ResetConnectionInput): Connection
|
resetConnection(input: ResetConnectionInput): Connection
|
||||||
@@ -244,12 +251,6 @@ input ExecuteFlowInput {
|
|||||||
stepId: String!
|
stepId: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input CreateUserInput {
|
|
||||||
fullName: String!
|
|
||||||
email: String!
|
|
||||||
role: UserRoleInput!
|
|
||||||
}
|
|
||||||
|
|
||||||
input UserRoleInput {
|
input UserRoleInput {
|
||||||
id: String
|
id: String
|
||||||
}
|
}
|
||||||
@@ -344,11 +345,6 @@ type User {
|
|||||||
updatedAt: String
|
updatedAt: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserWithAcceptInvitationUrl {
|
|
||||||
user: User
|
|
||||||
acceptInvitationUrl: String
|
|
||||||
}
|
|
||||||
|
|
||||||
type Role {
|
type Role {
|
||||||
id: String
|
id: String
|
||||||
name: String
|
name: String
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
export const CREATE_USER = gql`
|
|
||||||
mutation CreateUser($input: CreateUserInput) {
|
|
||||||
createUser(input: $input) {
|
|
||||||
user {
|
|
||||||
id
|
|
||||||
email
|
|
||||||
fullName
|
|
||||||
role {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
acceptInvitationUrl
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
Reference in New Issue
Block a user