31 lines
719 B
Python
31 lines
719 B
Python
|
from app import db
|
||
|
from database.models import *
|
||
|
from database.schema import *
|
||
|
from marshmallow import ValidationError
|
||
|
|
||
|
|
||
|
def insert_data(schema, data):
|
||
|
instance = validate_data(schema=schema, data=data)
|
||
|
db.session.add(instance)
|
||
|
db.session.commit()
|
||
|
|
||
|
|
||
|
def delete_data(id):
|
||
|
db.session.delete(data)
|
||
|
db.session.commit()
|
||
|
|
||
|
|
||
|
def update_otp(user_id, otp):
|
||
|
db.session.query(table="Users").filter_by(id=user_id).update(dict(otp=otp))
|
||
|
db.session.commit()
|
||
|
|
||
|
|
||
|
def validate_data(schema, data):
|
||
|
validation_schema = schema + "Schema()"
|
||
|
instance = validation_schema
|
||
|
try:
|
||
|
output = instance.load(data).data
|
||
|
return output
|
||
|
except ValidationError as err:
|
||
|
print(err.messages)
|