diff options
Diffstat (limited to 'api/valid.py')
-rw-r--r-- | api/valid.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/api/valid.py b/api/valid.py new file mode 100644 index 0000000..f407460 --- /dev/null +++ b/api/valid.py @@ -0,0 +1,21 @@ +from db import cursor + + +def validate(id, type): + types = { + "user": ["user_id", "users"], + "game": ["game_id", "games"], + } + fields = types[type] + query = cursor.execute( + f"select {fields[0]} from {fields[1]} where {fields[0]} = ?", [id] + ).fetchone() + return bool(query) + + +def user_id(user_id): + return validate(user_id, "user") + + +def game_id(game_id): + return validate(game_id, "game") |