mirror of https://gitlab.com/akasroua/covot
43 lines
953 B
Python
43 lines
953 B
Python
from sqlalchemy import or_
|
|
|
|
from database import SessionLocal, engine, models
|
|
from database.models import Users
|
|
|
|
db = SessionLocal()
|
|
|
|
|
|
def search_database(id):
|
|
return db.query(Users).filter(
|
|
or_(Users.correo_institucional == id, Users.numero_de_documento == id)
|
|
)
|
|
|
|
|
|
def insert_data(data):
|
|
item = Users(**data)
|
|
db.add(item)
|
|
db.commit()
|
|
db.refresh(item)
|
|
|
|
|
|
def create_database(data):
|
|
models.Base.metadata.create_all(bind=engine)
|
|
existing_row = search_database(data["correo_institucional"])
|
|
if existing_row:
|
|
return
|
|
insert_data(data)
|
|
|
|
|
|
def save_attribute(attribute, data):
|
|
key = eval("Users." + attribute)
|
|
db.query(Users).filter(
|
|
or_(Users.correo_institucional == id, Users.numero_de_documento == id)
|
|
).update({key: data})
|
|
|
|
|
|
def verify_code(id, code):
|
|
db_record = search_database(id=id)
|
|
valid_code = code == db_record
|
|
if valid_code:
|
|
return True
|
|
return False
|