3-Layered Architecture
// 회원가입
signUp = async (req, res, next) => {
try {
const { name, email, password, passwordRe, description } = req.body;
const createdUser = await this.usersService.createUser(name, email, password, passwordRe, description);
return res.status(201).json({ message: '성공적으로 회원가입', createdUser: createdUser });
} catch (error) {
next(error);
}
};
createUser = async (name, email, password, passwordRe, description) => {
try {
if (!name || !email || !password || !passwordRe) {
throw new Error('값을 모두 입력해라');
}
if (password !== passwordRe) {
throw new Error('입력한 비밀번호가 다름');
}
const isExistUser = await this.usersRepository.findUserByEmail(email);
if (isExistUser) {
throw new Error('이미 존재하는 email 입니다');
}
const sortPassword = await bcrypt.hash(password, 11);
const createdUser = await this.usersRepository.createUser(name, email, sortPassword, description);
return createdUser;
} catch (error) {
throw error;
}
};
createUser = async (name, email, sortPassword, description) => {
const createdUser = await prisma.Users.create({
data: { name, email, password: sortPassword, description },
});
return createdUser;
};