feat: Convert all mutation files to js

This commit is contained in:
Faruk AYDIN
2023-12-28 13:53:16 +01:00
parent 47dd5a1949
commit 8d6f0f8e9e
42 changed files with 229 additions and 706 deletions

View File

@@ -0,0 +1,38 @@
import User from '../../models/user';
import Role from '../../models/role';
const createUser = async (_parent, params, context) => {
context.currentUser.can('create', 'User');
const { fullName, email, password } = params.input;
const existingUser = await User.query().findOne({
email: email.toLowerCase(),
});
if (existingUser) {
throw new Error('User already exists!');
}
const userPayload = {
fullName,
email,
password,
};
try {
context.currentUser.can('update', 'Role');
userPayload.roleId = params.input.role.id;
} catch {
// void
const role = await Role.query().findOne({ key: 'admin' });
userPayload.roleId = role.id;
}
const user = await User.query().insert(userPayload);
return user;
};
export default createUser;