Skip to content
Snippets Groups Projects
Commit 059ea81f authored by 조대희's avatar 조대희
Browse files

feat: 사용자 존재 유효성 검사 (#7)

parent aa60d98a
Branches
No related tags found
2 merge requests!31Develop,!8[#7] Friend 서비스 로직 개발
...@@ -4,12 +4,25 @@ const User = require('../models/user'); ...@@ -4,12 +4,25 @@ const User = require('../models/user');
class friendService { class friendService {
/**
* User 존재 여부 유효성 검사
*/
async validUser(userId) {
const user = await User.findByPk(userId);
if (!user) {
throw new Error('User not found');
}
return user;
}
/** /**
* 친구 요청 보내기 * 친구 요청 보내기
* 나 자신에게 보내기 or 이미 존재하는 친구 -> X * 나 자신에게 보내기 or 이미 존재하는 친구 -> X
* 이후, PENDING 상태로 변환 -> 수락/거절에 따라 변화 * 이후, PENDING 상태로 변환 -> 수락/거절에 따라 변화
*/ */
async sendFriendRequest(userId, friendId) { async sendFriendRequest(userId, friendId) {
await this.validUser(userId);
await this.validUser(friendId);
if (userId === friendId) { if (userId === friendId) {
throw new Error('Cannot send friend request to yourself'); throw new Error('Cannot send friend request to yourself');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment