Profile Friend stuff
This commit is contained in:
@@ -47,6 +47,15 @@ export async function POST(req: Request) {
|
||||
userData = await db.users.update(userData.id, { inventory: inventoryData });
|
||||
if (!userData) return NextResponse.json({ message: "Failed to update inventory" }, { status: 500 });
|
||||
}
|
||||
|
||||
let friends = formData.get("friends");
|
||||
if(friends) {
|
||||
let friendsData = userData.friends;
|
||||
if (!friendsData) friendsData = [];
|
||||
friendsData.push(friends.toString());
|
||||
userData = await db.users.update(userData.id, { friends: friendsData });
|
||||
if (!userData) return NextResponse.json({ message: "Failed to update friends" }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "User updated successfully", user: userData }, { status: 200 });
|
||||
} catch (error) {
|
||||
|
||||
@@ -34,3 +34,38 @@ export async function GET(req: Request, { params }: any) {
|
||||
return NextResponse.json({ message: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// for making friend requests
|
||||
export async function POST(req: Request, { params }: any) {
|
||||
try {
|
||||
if (!(await authenticateUser())) return;
|
||||
|
||||
const { id } = params;
|
||||
|
||||
let user = await db.users.findById(id);
|
||||
|
||||
let formData = await req.formData();
|
||||
if (!formData) return NextResponse.json({ message: "No form data found" }, { status: 400 });
|
||||
|
||||
let friendCode = formData.get("friendCode");
|
||||
|
||||
if (!friendCode) return NextResponse.json({ message: "No friend code found" }, { status: 400 });
|
||||
let friendCodeString = friendCode.toString();
|
||||
if (friendCodeString.length !== 5) return NextResponse.json({ message: "Invalid friend code" }, { status: 400 });
|
||||
|
||||
let requests = user.requests || [];
|
||||
|
||||
if (requests.includes(friendCodeString)) {
|
||||
return NextResponse.json({ message: "Already sent a friend request" }, { status: 400 });
|
||||
}
|
||||
|
||||
requests.push(friendCodeString);
|
||||
user = await db.users.update(user.id, { requests });
|
||||
if (!user) return NextResponse.json({ message: "Failed to update requests" }, { status: 500 });
|
||||
return NextResponse.json({ message: "Friend request sent successfully" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error("Error sending friend request:", error);
|
||||
return NextResponse.json({ message: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user