createAccount.js 760 Bytes
import { prisma, generateToken, changePhoneNumber } from "../../../utils";
import bcrypt from "bcryptjs";

export default {
  Mutation: {
    createAccount: async (_, args) => {
      const { name, password, email, bio, avatarUrl, phoneNum } = args;
      const encryptPw = await bcrypt.hash(password, 10);
      // TODO: Find user's country code and change new phone number value
      const newPhoneNumber = await changePhoneNumber(phoneNum, "+82");
      const user = await prisma.user.create({
        data: {
          name,
          email,
          bio,
          avatarUrl,
          password: encryptPw,
          phoneNum: newPhoneNumber,
        },
      });
      const token = generateToken(user.id);
      return { token, user };
    },
  },
};