def deposit_account(account_data):
        """
        Deposit BankAccount and generate Transaction record
        :returns dict:, Ie {'message': 'Your ....'}
        """
        if not get(account_data, ['amount']) or not get(
                account_data, ['account_number']):
            raise BadRequest

        bank_account = BankAccountManager.get_account(
            account_data['account_number'])
        if not bank_account:
            raise BankAccountNotFound(account_data['account_number'])

        new_balance = bank_account.balance + account_data['amount']
        update_data = {'balance': new_balance}
        BankAccountManager.update(update_data, bank_account)

        transaction = {
            'account_number': account_data['account_number'],
            'currency': 'COP',
            'type': 'DEPOSIT',
            'previous_balance': bank_account.balance,
            'trm': 0,
            'amount': account_data['amount']
        }
        TransactionManager.save(transaction)

        return {'balance': new_balance}
示例#2
0
 def validate_user_account(user_data):
     """
     Validate User account by user_id and pin
     :param user_data: dict, Ie {'user_id': 10, 'pin': 20}
     :returns Object, Ie {'user_id': 10, 'pin': 20 ....}
     """
     return User.objects(user_id=get(user_data, ['user_id']),
                         pin=get(user_data, ['pin'])).first()
 def get_trigger(self, trigger):
     """
     Get the workflow trigger
     """
     transitions = trigger.get('transitions')
     step_id = get(next(iter(transitions)), ['target'], None)
     return step_id
示例#4
0
    def save(user_data):
        """
        Save User model
        :param user_data: Data to be store in User collection. Ie {id: 10}
        :returns dict, Ie {'message': 'User created'}
        """
        if not get(user_data, ['user_id']) or not get(user_data, ['pin']) or \
                not get(user_data, ['user_name']) or not get(user_data, ['password']):
            raise BadRequest

        user = UserManager.save(user_data)
        if not user:
            raise UserInvalidVerification(user_data['user_id'],
                                          user_data['pin'])

        return {'message': 'User created'}
示例#5
0
    def validate_user_account(user_data):
        """
        Validate user account by filters user_id and pin
        :param user_data: Filters to get users. Ie {id: 10}
        :returns dict, Ie {'is_valid': True}
        """
        if not get(user_data, ['user_id']) or not get(user_data, ['pin']):
            raise BadRequest

        is_valid = {'is_valid': True}

        user = UserManager.validate_user_account(user_data)
        if not user:
            is_valid = {'is_valid': False}

        return is_valid
示例#6
0
    def get_auth_user(user_data):
        """
        Get Auth User by user_name and password
        :param user_data: Filters to get users. Ie {user_id: 10}
        :returns Object, Ie {'user_id': 10, 'pin': 20 ....}
        """
        if not get(user_data, ['user_name']) or not get(
                user_data, ['password']):
            raise BadRequest

        user = UserManager.get_auth_user(user_data=user_data)
        if not user:
            raise UserAuthNotFound(user_data['user_name'],
                                   user_data['password'])

        return user
 def get_trm(self):
     """
     Get current TRM based on a specific date
     :param: trm_date: String, Ie '2021-05-06'
     :return json_response: JSON object, Ie, {
             "data":{
                 "unit":"COP",
                 "validityFrom":"2019-02-02T05:00:00.000Z",
                 "validityTo":"2019-02-04T05:00:00.000Z",
                 "value":3102.61,
                 "success":true
             },
             "dev":"Jonhatan Fajardo",
             "web":"www.makaw.dev"
         }
     """
     current_date = datetime.today().strftime('%Y-%m-%d')
     trm_response = get_current_trm(current_date)
     if get(trm_response, ['data']) and get(trm_response, ['data', 'success']):
         self.trm = get(trm_response, ['data', 'value'])
    def withdrawal_account(account_data):
        """
        Withdrawal BankAccount and generate Transaction record
        :returns dict:, Ie {'message': 'Your ....'}
        """
        if not get(account_data, ['amount']) or not get(account_data, ['account_number']) or \
                not get(account_data, ['currency']) or get(account_data, ['currency']) not in ['COP', 'USD']:
            raise BadRequest

        if account_data['currency'] == 'USD' and not get(
                account_data, ['trm']):
            raise BadRequest

        bank_account = BankAccountManager.get_account(
            account_data['account_number'])
        if not bank_account:
            raise BankAccountNotFound(account_data['account_number'])

        if account_data['currency'] == 'USD':
            account_data[
                'amount'] = account_data['amount'] * account_data['trm']

        if account_data['amount'] > bank_account.balance:
            return {'balance': -1}

        new_balance = bank_account.balance - account_data['amount']
        update_data = {'balance': round(new_balance)}
        BankAccountManager.update(update_data, bank_account)

        transaction = {
            'account_number': account_data['account_number'],
            'currency': account_data['currency'],
            'type': 'WITHDRAWAL',
            'previous_balance': bank_account.balance,
            'trm': account_data['trm'],
            'amount': account_data['amount']
        }
        TransactionManager.save(transaction)

        return {'balance': new_balance}
 def get_params(self, step_params):
     """
     Get params from workflows steps
     :param step_params:
     :return: {'key': 'sdfsdf', 'value': 'asdasd'}
     """
     params = {}
     for key, step_param in step_params.items():
         from_id = step_param.get('from_id')
         param_id = step_param.get('param_id')
         param_value = get(self.steps, [from_id, 'params', param_id]) if from_id else step_param.get('value')
         params[key] = param_value
     return params
 def validate_conditions(self, conditions):
     """
     Validate conditions results
     :param conditions: array
     :return: dict
     """
     result = True
     for condition in conditions:
         from_id = condition.get('from_id')
         field_id = condition.get('field_id')
         value_result = get(self.workflow_session, [from_id, field_id])
         operator = condition['operator']
         value_condition = condition['value']
         result = self.switcher_operator[operator](value_result, value_condition)
         if not result:
             break
     return result