aboutsummaryrefslogtreecommitdiff
path: root/api/valid.py
blob: f4074603b31b6470e6d2b8e5c3cbc62532c5352e (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")