Skip to content

Commit

Permalink
feat: Send friend request to external server and handle response
Browse files Browse the repository at this point in the history
  • Loading branch information
tako0614 committed Jun 16, 2024
1 parent bc66629 commit 73d43b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 26 additions & 1 deletion routes/api/v1/friends/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,39 @@ export const handler = {
status: 200,
})
} else {
//外部サーバーにリクエストを送る
const serverDomain = splitUserName(friendName)?.domain
const myFriendInfo = await Friends.findOne({ user: userid })
if (myFriendInfo == null) {
await Friends.create({ user: userid })
}
const frienduuidres = await takosfetch(
`${serverDomain}/api/v1/server/users/${friendName}/uuid`,
)
if(!frienduuidres){
console.log("frienduuidres is null")
return new Response(
JSON.stringify({ status: "error" }),
{
headers: { "Content-Type": "application/json" },
status: 400,
},
)
}
if(frienduuidres.status !== 200){
console.log("frienduuidres is not 200")
return new Response(
JSON.stringify({ status: "error" }),
{
headers: { "Content-Type": "application/json" },
status: 400,
},
)
}
const frienduuid = (await frienduuidres.json()).uuid
const isAlredyFriend = myFriendInfo?.friends.some((
friend: any,
) => friend.userid === friendName)
) => friend.userid === frienduuid)
if (isAlredyFriend) {
console.log("isAlredyFriend")
return new Response(
Expand Down
3 changes: 2 additions & 1 deletion routes/api/v1/server/friends/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ export const handler = {
status: 400,
})
}
//↓↓
const existingFriend = await friends.findOne({
user: requesterUserUUID,
"friends.userid": recipientUserName,
})
if (existingFriend) {
if (!existingFriend) {
return new Response(
JSON.stringify({
status: false,
Expand Down

0 comments on commit 73d43b0

Please sign in to comment.