feat: Convert all mutation files to js
This commit is contained in:
27
packages/backend/src/graphql/mutations/register-user.ee.js
Normal file
27
packages/backend/src/graphql/mutations/register-user.ee.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import User from '../../models/user';
|
||||
import Role from '../../models/role';
|
||||
|
||||
const registerUser = async (_parent, params) => {
|
||||
const { fullName, email, password } = params.input;
|
||||
|
||||
const existingUser = await User.query().findOne({
|
||||
email: email.toLowerCase(),
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
throw new Error('User already exists!');
|
||||
}
|
||||
|
||||
const role = await Role.query().findOne({ key: 'user' });
|
||||
|
||||
const user = await User.query().insert({
|
||||
fullName,
|
||||
email,
|
||||
password,
|
||||
roleId: role.id,
|
||||
});
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export default registerUser;
|
Reference in New Issue
Block a user