update many files
This commit is contained in:
+29
-14
@@ -81,39 +81,54 @@ def search_room(
|
||||
return room["name"]
|
||||
|
||||
|
||||
def accept_room(
|
||||
user_id,
|
||||
invite_code
|
||||
):
|
||||
def accept_room(user_id, invite_code):
|
||||
|
||||
query = """
|
||||
SELECT id
|
||||
FROM rooms
|
||||
WHERE invite_code = ?
|
||||
"""
|
||||
|
||||
room = fetch_one(
|
||||
query,
|
||||
(
|
||||
invite_code,
|
||||
)
|
||||
(invite_code,)
|
||||
)
|
||||
|
||||
if room is None:
|
||||
return None
|
||||
|
||||
room_id = room["id"]
|
||||
role = DEFAULT_ROLE
|
||||
query2 = """
|
||||
INSERT INTO "main"."room_members"
|
||||
("room_id", "user_id", "role")
|
||||
VALUES (?, ?, ?);
|
||||
|
||||
# check dubbele join
|
||||
existing = fetch_one(
|
||||
"""
|
||||
SELECT id
|
||||
FROM room_members
|
||||
WHERE room_id = ?
|
||||
AND user_id = ?
|
||||
""",
|
||||
(
|
||||
room_id,
|
||||
user_id
|
||||
)
|
||||
)
|
||||
|
||||
if existing:
|
||||
return None
|
||||
|
||||
|
||||
query = """
|
||||
INSERT INTO room_members
|
||||
(room_id, user_id, role)
|
||||
VALUES (?, ?, ?)
|
||||
"""
|
||||
|
||||
member_id = execute(
|
||||
query2,
|
||||
query,
|
||||
(
|
||||
room_id,
|
||||
user_id,
|
||||
role
|
||||
"member"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user