fix: delete current user in deleteUser mutation
This commit is contained in:
@@ -1,20 +1,11 @@
|
|||||||
import User from '../../models/user';
|
import Context from '../../types/express/context';
|
||||||
import deleteUserQueue from '../../queues/delete-user.ee';
|
import deleteUserQueue from '../../queues/delete-user.ee';
|
||||||
import { Duration } from 'luxon';
|
import { Duration } from 'luxon';
|
||||||
|
|
||||||
type Params = {
|
const deleteUser = async (_parent: unknown, params: never, context: Context) => {
|
||||||
input: {
|
const id = context.currentUser.id;
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteUser = async (_parent: unknown, params: Params) => {
|
await context.currentUser.$query().delete();
|
||||||
const { id } = params.input;
|
|
||||||
await User
|
|
||||||
.query()
|
|
||||||
.findById(id)
|
|
||||||
.delete()
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
const jobName = `Delete user - ${id}`;
|
const jobName = `Delete user - ${id}`;
|
||||||
const jobPayload = { id };
|
const jobPayload = { id };
|
||||||
|
@@ -54,7 +54,7 @@ type Mutation {
|
|||||||
updateStep(input: UpdateStepInput): Step
|
updateStep(input: UpdateStepInput): Step
|
||||||
deleteStep(input: DeleteStepInput): Step
|
deleteStep(input: DeleteStepInput): Step
|
||||||
createUser(input: CreateUserInput): User
|
createUser(input: CreateUserInput): User
|
||||||
deleteUser(input: DeleteUserInput): Boolean
|
deleteUser: Boolean
|
||||||
updateUser(input: UpdateUserInput): User
|
updateUser(input: UpdateUserInput): User
|
||||||
forgotPassword(input: ForgotPasswordInput): Boolean
|
forgotPassword(input: ForgotPasswordInput): Boolean
|
||||||
resetPassword(input: ResetPasswordInput): Boolean
|
resetPassword(input: ResetPasswordInput): Boolean
|
||||||
@@ -340,10 +340,6 @@ input CreateUserInput {
|
|||||||
password: String!
|
password: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input DeleteUserInput {
|
|
||||||
id: String
|
|
||||||
}
|
|
||||||
|
|
||||||
input UpdateUserInput {
|
input UpdateUserInput {
|
||||||
email: String
|
email: String
|
||||||
password: String
|
password: String
|
||||||
|
@@ -27,13 +27,7 @@ export default function DeleteAccountDialog(props: TDeleteAccountDialogProps) {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleConfirm = React.useCallback(async () => {
|
const handleConfirm = React.useCallback(async () => {
|
||||||
await deleteUser({
|
await deleteUser();
|
||||||
variables: {
|
|
||||||
input: {
|
|
||||||
id: currentUser.id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
authentication.updateToken('');
|
authentication.updateToken('');
|
||||||
await apolloClient.clearStore();
|
await apolloClient.clearStore();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { gql } from '@apollo/client';
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
export const DELETE_USER = gql`
|
export const DELETE_USER = gql`
|
||||||
mutation DeleteUser($input: DeleteUserInput) {
|
mutation DeleteUser {
|
||||||
deleteUser(input: $input)
|
deleteUser
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
Reference in New Issue
Block a user