feat: Implement createUser mutation

This commit is contained in:
Faruk AYDIN
2023-02-18 14:49:12 +01:00
parent aeec2377c1
commit b8b453aba0
4 changed files with 37 additions and 0 deletions

View 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;