Exemple #1
0
 def catch_order(self, _order_id, _delivery_id, offer_info):
     from src.app import db
     from src.auth.models.order_table import OrderModel
     from src.auth.services.user_service import UserService
     from src.auth.models.user_table import NormalUserModel, DeliveryUserModel
     order = OrderModel.get_instance(_order_id)
     user_service = UserService()
     if order.payWithPoints: #chequeo que el que acepto la orden sea un usuario normal, no delivery
         try:
             delivery_user = user_service.get_normal_user(_delivery_id)
             user = user_service.get_normal_user(order.user_id)
             user.favourPoints -= offer_info["points"]
             order.favourPoints = offer_info["points"]
         except:
             raise NotFoundException("ID invalido: Solo los usuarios comunes pueden aceptar favores")
     else:
         try:
             order.delivery_price = offer_info["delivery_price"]
             order.delivery_pay = offer_info["delivery_pay"]
             user_service.get_delivery_user(_delivery_id)
         except:
             raise NotFoundException("ID invalido: Delivery inexistente")  
     user_service.user_start_working(_delivery_id, _order_id)
     user_service.wait_order(order.user_id)
     order.delivery_id = _delivery_id
     self.change_order_state(_order_id, "onWay")
     if order.discount:
         user_service.discount_favour_point(order.user_id, 10)
     order.save()
     return order
Exemple #2
0
def cancel_premium_subscription(_id):
    service = UserService()
    user = service.get_normal_user(_id)
    if not user: 
        raise NotFoundException("user with that id doesn't exist.")
    service.update_user(int(_id),{"suscripcion": "flat"})
    return jsonify({"msg":"subscription updated to flat"}),200
Exemple #3
0
 def user_order_by_favour(self, user_id, points_for_favour):
     from src.auth.models.user_table import NormalUserModel
     try:
         user = self.get_user(user_id)
     except NotFoundException:
         raise NotFoundException(
             "ID invalido: Solo los usuarios comunes pueden solicitar favores"
         )
     return (user.favourPoints >= points_for_favour)
Exemple #4
0
def set_premium_subscription(_id):
    service = UserService()
    user = service.get_normal_user(_id)
    if not user: 
        raise NotFoundException("user with that id doesn't exist.")
    content = request.get_json()
    card = card_schema.load(content)
    service.update_user(int(_id),{"suscripcion": "premium"})
    return jsonify({"msg":"subscription updated to premium"}),200
Exemple #5
0
 def _get_userModel_email(self, email):
     from src.auth.models.user_table import UserModel
     try:
         user = UserModel.query.filter_by(email=email).one()
     except NoResultFound:
         raise NotFoundException("No user with provided email")
     except:
         raise
     else:
         return user
Exemple #6
0
 def get_sample_products(self, quantity):
     filename = 'src/auth/services/default_products.json'
     try:
         with open(filename, 'r') as f:
             datastore = json.load(f)
             products = random.sample(datastore["products"], quantity)
     except:
         raise NotFoundException(
             "Error con el archivo '{}'".format(filename))
     else:
         return products
Exemple #7
0
 def update_user(self, _id, data):
     try:
         user = self.get_normal_user(_id)
     except Exception:
         user = self.get_delivery_user(_id)
     except Exception:
         user = None
     finally:
         if not user:
             raise NotFoundException(
                 "El user id que se quiere actualziar es invalido")
         user_data = self.get_user(_id, dict_format=True)
         user_data.update(data)
         assert user.update(user_data) == True
Exemple #8
0
 def set_order_price(self, order_id):
     from src.auth.models.order_table import OrderProductsModel
     from src.auth.models.product_table import ProductModel
     order = self.get_order(order_id)
     order_products = OrderProductsModel.query.filter_by(order_id=order_id)
     price = 0.0
     for order_product in order_products:
         product  = ProductModel.query.get(order_product.product_id)
         if not product:
             raise NotFoundException("El producto que quiere agregar no existe")
         price += (product.price * order_product.units)
     if order.discount:    
         price = price - 0.2*price
     order.price = price
     order.save()
Exemple #9
0
 def get_instance(cls, id):
     response = cls.query.get(id)
     if not response:
         raise NotFoundException("Invalid ID")
     return response
Exemple #10
0
 def get_user(user_id):
     response = NormalUserModel.query.get(user_id)
     if not response:
         raise NotFoundException("Invalid ID")
     return response
Exemple #11
0
 def get_delivery(user_id):
     response = DeliveryUserModel.query.get(user_id)
     if not response:
         raise NotFoundException("Invalid ID")
     return response
Exemple #12
0
 def get_product(product_id):
   response = ProductModel.query.get(product_id)
   if not response:
     raise NotFoundException("Invalid ID")
   return response
Exemple #13
0
 def get_offer(offer_id):
   response = OrderOffersModel.query.get(offer_id)
   if not response:
       raise NotFoundException("Invalid ID")
   return response