feat: Implement createUser mutation
This commit is contained in:
28
packages/backend/src/graphql/mutations/create-user.ee.ts
Normal file
28
packages/backend/src/graphql/mutations/create-user.ee.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import User from '../../models/user';
|
||||
|
||||
type Params = {
|
||||
input: {
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
};
|
||||
|
||||
const createUser = async (_parent: unknown, params: Params) => {
|
||||
const { email, password } = params.input;
|
||||
|
||||
const existingUser = await User.query().findOne({ email });
|
||||
|
||||
if (existingUser) {
|
||||
throw new Error('User already exists!');
|
||||
}
|
||||
|
||||
const user = await User.query().insert({
|
||||
email,
|
||||
password,
|
||||
role: 'user',
|
||||
});
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export default createUser;
|
Reference in New Issue
Block a user