팀 프로젝트를 하면서 Code Convention을 처음 정립하였다.
회원가입 API를 제작할 때 유효성 검사로 정규표현식을 사용하였다.
// RegExp 안에 닉네임을 삽입
const regexp = await new RegExp(`${nickname}`);
// 비밀번호 안에 닉네임이 들어가 있는 경우
// 닉네임이 들어가있는 경우 test 메소드를 통해 true 반환
if (regexp.test(password)) {
return res.status(412).json({ errorMessage: '패스워드에 닉네임이 포함되어 있습니다.' });
}
또한 중복된 닉네임이 있는 경우도 한번 작성하였다.
const existUser = await User.findOne({ nickname });
// existUser 객체가 있는 경우 (중복된 닉네임이 있는 경우)
if (existUser) {
return res.status(412).json({ errorMessage: '중복된 닉네임입니다.' });
}