sdy

update user's phone number value

import { prisma, generateToken } from "../../../utils";
import { prisma, generateToken, changePhoneNumber } from "../../../utils";
import bcrypt from "bcryptjs";
export default {
......@@ -6,6 +6,8 @@ export default {
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,
......@@ -13,7 +15,7 @@ export default {
bio,
avatarUrl,
password: encryptPw,
phoneNum,
phoneNum: newPhoneNumber,
},
});
const token = generateToken(user.id);
......
......@@ -23,6 +23,13 @@ export const isAuthenticated = (request) => {
return;
};
export const changePhoneNumber = (phoneNum, locationNum) => {
var leftStr = locationNum;
var rightStr = phoneNum.slice(1, phoneNum.length());
var newStr = leftStr + rightStr;
return newStr;
};
export const generateSecret = () => {
const randomNumber = Math.floor(Math.random() * adjectives.length);
return `${adjectives[randomNumber]} ${nouns[randomNumber]}`;
......