Ejemplo n.º 1
0
def listallcoupons():
    error = False
    coupon = Coupon()
    try:
        results = coupon.listall()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            return jsonify({'results': results})
Ejemplo n.º 2
0
def deleteCoupon():
    error = False
    id = request.json['id']
    new = Coupon()
    new.id = id
    try:
        new.delete()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            return jsonify({'result': 'success'})
Ejemplo n.º 3
0
def addCoupon():
    error = False
    pc = request.json['pc']
    cad_date = request.json['cad_date']
    new = Coupon(pc, cad_date)
    try:
        new.add()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            return jsonify({'result': 'success'})
Ejemplo n.º 4
0
def modShipping():
    error = False
    id = request.json['id']
    pc = request.json['pc']
    cad_date = request.json['cad_date']
    used = request.json['used']
    new = Coupon(pc, cad_date, used, id)
    try:
        new.mod()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            return jsonify({'result': 'success'})
Ejemplo n.º 5
0
def getPurchaseInfo():
    error = False
    result = {}
    id = request.json['id']
    purch = Purchase()
    purch.id = id
    try:
        purch.get()
        result['purchase'] = purch.json()
        ship = Shipping()
        ship.id = id
        ship.get()
        if (ship.id != None):
            result['shipping'] = ship.json()
        if (purch.id_coupon != None):
            coup = Coupon()
            coup.id = purch.id_coupon
            coup.get()
            result['coupon'] = coup.json()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            return jsonify({'result': 'success', 'data': result})
Ejemplo n.º 6
0
def getCoupon():
    error = False
    id = request.json['id']
    new = Coupon()
    new.id = id
    try:
        new.get()
    except (Exception) as err:
        error = True
        return handleError(err)
    finally:
        if not (error):
            result = new.json()
            return jsonify({'result': 'success', 'data': result})
Ejemplo n.º 7
0
from classes import User, Customer, Type, Role, Chat, Message, Product, Color_size, Coupon, Shipping, Purchase, Purchxitem, Reservation, Wishlist, Review
from ddbb_connect import logInUser, logInUser2
from mp_api import pagar
from flask_cors import CORS
from timeloop import Timeloop
from datetime import timedelta


def handleError(error):
    detail = ''
    for item in error.args:
        detail = detail + item
    return jsonify({'result': 'error', 'type': detail}), 500


coupon = Coupon()
reservation = Reservation()

app = Flask(__name__)
CORS(app)

tl = Timeloop()


@tl.job(interval=timedelta(seconds=3600))
def updateDates():
    try:
        coupon.check_dates()
        reservation.check_dates()
        print('dates checked')
    except (Exception) as err: