aboutsummaryrefslogtreecommitdiff
path: root/api/valid.py
blob: 1c63703bd61e50b2f14c746bb2707d5a5c9efc5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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")