def add_voucher_to_user_wallet(user_selected_voucher, user_id, username):
    expiry_date = TimeManager.gen_expiry_date()
    voucher_id_in_db = user_selected_voucher[1]
    voucher_title = user_selected_voucher[2]
    exchange_fee = user_selected_voucher[9]

    voucher_to_be_added_into_db = {
        'telegram_id': user_id,
        'asset_type': 'coupon',
        'asset_id': voucher_id_in_db,
        'asset_value': 1,
        'expiry_date': expiry_date
    }

    result = UserManager.add_user_voucher(voucher_to_be_added_into_db)

    if result:
        exchange_voucher_id_to_be_updated = user_selected_voucher[8]

        VoucherManager.update_voucher_details(
            exchange_voucher_id_to_be_updated, 'exchangecoupons',
            'issueamount')

        UserManager.update_user_snapcoin_amt(exchange_fee, '-', user_id)
        UserManager.update_user_voucher_history(user_id, 'exchanged',
                                                voucher_id_in_db)

        return True

    LoggerManager.exception_logs(
        f"Error occurred while adding {voucher_title} voucher to user {username} ({user_id})'s wallet!"
    )
Пример #2
0
def add_coin_to_user_wallet(snapcoin_amount, arithmetic_operator, user_id,
                            username):
    result = UserManager.update_user_snapcoin_amt(snapcoin_amount,
                                                  arithmetic_operator, user_id)

    logging_message = f"{snapcoin_amount} to user {username} ({user_id})'s wallet!"

    if result:
        LoggerManager.general_logs(f"Successfully added {logging_message}")

        return True

    else:
        LoggerManager.exception_logs(
            f"Error occurred while adding {logging_message}")