🐛 Fixed multiple accept/deny of friend request

master
Alix JEUDI--LEMOINE 3 months ago
parent f772a9b022
commit e553fcc881

@ -243,12 +243,19 @@ async def delete_friend(id: str, current_user: User = Depends(get_current_user))
)
async def accept_friend(id: str, current_user: User = Depends(get_current_user)):
try:
result = friends_collection.update_one({"_id": ObjectId(id)}, {"$set": {"status": "accepted"}})
check_friend = friends_collection.find_one({"_id": ObjectId(id)})
if check_friend is None: friend_not_found()
if check_friend["status"] != "pending":
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Friend request already accepted"
)
friends_collection.update_one({"_id": ObjectId(id)}, {"$set": {"status": "accepted"}})
except bson.errors.InvalidId:
objectid_misformatted()
if result.matched_count == 0: friend_not_found()
return {"message": "Friend request accepted"}
@app.post(

Loading…
Cancel
Save