Exemplo n.º 1
0
    def get(self):
        """
        Retrieves the information of all the Cards of the current user.

        :return: JSON object with all the Cards
        """
        user_id = get_jwt_identity()
        user = UserModel.get_by_id(user_id)
        return [card.json() for card in CardModel.get_user_cards(user)], 200
Exemplo n.º 2
0
    def get(self):
        """
        Retrieves the information of all the payments of the current user.

        :return: JSON object with all the payments
        """
        user_id = get_jwt_identity()
        user = UserModel.get_by_id(user_id)
        return [campaign.json() for campaign in PaymentModel.get_user_payments(user)], 200
Exemplo n.º 3
0
    def get(self):
        """
        Retrieves the information of all the scripts of the current user.

        :return: JSON object with all the scripts
        """
        user_id = get_jwt_identity()
        user = UserModel.get_by_id(user_id)
        return [
            script.json() for script in ScriptModel.get_user_scripts(user)
        ], 200
Exemplo n.º 4
0
 def send_messages(self):
     user_id = get_jwt_identity()
     user = User.get_by_id(user_id)
     messages_to_send = self.prepare_messages()
     total_cost = len(messages_to_send)* user.sms_cost
     if total_cost < user.balance and user.user_type == "pre":
         raise NotEnoughBalanceToSendPackageError(f"El usuario cuenta con {user.balance} y se necesita {total_cost}")
     [message.send() for message in messages_to_send]
     user.balance -= (messages_to_send * user.sms_cost)
     user.update_mongo()
     return messages_to_send
Exemplo n.º 5
0
    def get(self):
        """
        Retrieves the information of all the messages of a certain package.

        :return: JSON object with all the messages
        """
        user_id = get_jwt_identity()
        user = UserModel.get_by_id(user_id)
        return [
            message.json()
            for message in MessageModel.get_package_messages(user)
        ], 200
Exemplo n.º 6
0
    def post(self):
        """
        Inserts a new script to the current user.

        :return: JSON object with the newly created script
        """
        try:
            data = PARSER.parse_args()
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return ScriptModel.add(user, data), 200
        except UserException as e:
            return Response(message=e.message).json(), 401
Exemplo n.º 7
0
    def delete(self, card_id):
        """
        Deletes the card with the given id in the parameters.

        :param card_id: The id of the card to be deleted from the user

        :return: JSON object with the remaining cards
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return [card.json()
                    for card in CardModel.delete(user, card_id)], 200
        except CardNotFoundException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 8
0
    def put(self):
        """
        Changes the status of the user's account (Active / Not Active)

        :return: Confirmation message
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            updated_user = UserModel.change_user_status(user)
            return Response(
                success=True,
                message="Status del usuario exitosamente actualizado".format(
                    updated_user.status)).json(), 200
        except UserException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 9
0
    def get(self, card_id):
        """
        Retrieves the information of the card with the given id in the parameters.

        :param card_id: The id of the card to be read from the user

        :return: JSON object with the requested card information
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return CardModel.get(user, card_id).json(), 200
        except CardNotFoundException as e:
            return Response(message=e.message).json(), 400
        except UserException as e:
            return Response(message=e.message).json(), 401
Exemplo n.º 10
0
    def put(self):
        """
        Changes the type of the user from Prepago to Pospago and viceversa

        :return: Confirmation message
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            updated_user = UserModel.change_user_type(user)
            return Response(
                success=True,
                message="Tipo de pago exitosamente actualizado".format(
                    updated_user.user_type)).json(), 200
        except UserException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 11
0
    def post(self):
        """
        Inserts a new Card to the current user.

        :return: JSON object with the newly created Card
        """
        try:
            data = PARSER.parse_args()
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return CardModel.add(user, data), 200
        except UserException as e:
            return Response(message=e.message).json(), 401
        except TokenizationFailedException as e:
            return Response(message=e.message).json(), 400
        except RepeatedCardException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 12
0
    def put(self, card_id):
        """
        Updated the card with the given id in the parameters and the JSON body.

        :param card_id: The id of the card to be updated from the user

        :return: JSON object with all the cards, with updated data
        """
        try:
            data = PARSER.parse_args()
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return [
                card.json() for card in CardModel.update(user, card_id, data)
            ], 200
        except CardNotFoundException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 13
0
    def delete(self, script_id):
        """
        Deletes the script with the given id in the parameters.

        :param script_id: The id of the script to be deleted from the user

        :return: JSON object with the remaining scripts
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            return [
                script.json()
                for script in ScriptModel.delete(user, script_id)
            ], 200
        except ScriptNotFoundException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 14
0
    def put(self):
        """
        Recovers the password of the user by creating a new password

        :return: Confirmation message
        """
        try:
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            # Falta implementar para recibir los datos correctos
            updated_user = UserModel.recover_password(user, user.email,
                                                      user.password)
            return Response(
                success=True,
                message="Status del usuario exitosamente actualizado".format(
                    updated_user.status)).json(), 200
        except UserException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 15
0
    def get(self, param):
        """
        Gets the information of a specific user, given its email or its ID

        :return: User object
        """
        if Utils.email_is_valid(param):
            try:
                user = UserModel.get_by_email(param)
                return user.json(), 200
            except UserException as e:
                return Response(message=e.message).json(), 400
        else:
            try:
                user = UserModel.get_by_id(param)
                return user.json(), 200
            except UserException as e:
                return Response(message=e.message).json(), 400
Exemplo n.º 16
0
    def put(self):
        """
        Updates the balance to the user given a new balance

        :return: Confirmation message
        """
        try:
            data = ChangeUserBalance.parser.parse_args()
            balance_to_change = data['balance']
            user_id = get_jwt_identity()
            user = UserModel.get_by_id(user_id)
            updated_user = UserModel.change_user_balance(
                user, balance_to_change)
            return Response(
                success=True,
                message="Balance del usuario exitosamente actualizado".format(
                    updated_user.balance)).json(), 200
        except UserException as e:
            return Response(message=e.message).json(), 400
Exemplo n.º 17
0
 def get(self, package_id):
     user_id = get_jwt_identity()
     user = UserModel.get_by_id(user_id)
     package = PackageModel.get_package(package_id, user)
     return package.get_package_data(user)
Exemplo n.º 18
0
 def post(self, package_id):
     user_id = get_jwt_identity()
     user = UserModel.get_by_id(user_id)
     package = PackageModel.get_package(package_id, user)
     return package.send_messages()
Exemplo n.º 19
0
 def get(self):
     user_id = get_jwt_identity()
     user = UserModel.get_by_id(user_id)
     return [package.json
             for package in PackageModel.get_packages(user)], 200
Exemplo n.º 20
0
 def post(self):
     data = parser.parse_args()
     user_id = get_jwt_identity()
     user = UserModel.get_by_id(user_id)
     return PackageModel.add_package(data, user).json(), 200
Exemplo n.º 21
0
 def get(self, package_id):
     user_id = get_jwt_identity()
     user = UserModel.get_by_id(user_id)
     return PackageModel.get_package(package_id, user).json(), 200