Параметры отображаются как неопределенные - Экспортированная функция JavaScript - PullRequest
0 голосов
/ 18 сентября 2018

Значения параметров моих экспортируемых функций возвращаются как неопределенные, остальные мои функции работают так же.Я надеюсь, что вы можете помочь!

Кстати - я знаю, что не все параметры включены, но до этого момента он еще не работал!

Моя функция, которая не работает в моем postRequests.jsfile:

exports.getRefundCalculationApiCall = function (itemId, ngrokUrl, domain, orderId) {
    console.log('ngrokurl 2' + ngrokUrl)
    console.log('domain2' + domain)
    console.log('orderId2' + orderId)
    console.log('itemId2' + itemId)
    httpRequest.post(
        `${ngrokUrl}/${domain}/${orderId}`,
        {
            json:
                {
                    "line_items": [
                        {
                            "line_item_id": itemId, "quantity": 1
                        }
                    ]
                }
        },
        function (error, resp, body) {
            if (!error && resp.statusCode == 200) {
                console.log(body)
                console.log('refund line items transactions information' + JSON.stringify(body.refund.transactions[0]));
                console.log('refund line items +++ information THIS IS THE ONE' + JSON.stringify(body.refund.refund_line_items[0]));
                refundAmount1 = JSON.stringify(body.refund.refund_line_items[0].price);
                order_id1 = body.refund.transactions[0].order_id;

                amount1 = body.refund.refund_line_items[0].amount;
                // constructing message to front-end with the refund expense.
                response = `Your refund amount would be ${refundAmount1}, for the item: ${itemName1}. Do you accept this and wish to initiate the returns process?`
                console.log('RESPONSE from getrefundCalc - work to FE?' + response)


                data = [details.chatuser, response]
                io.of('/main').to(socket.id).emit('response', data);

            }
            else {
                console.log('error' + error)
            }
        }
    )
}

вот я пытаюсь вызвать его в моем файле index.js:

console.log('ngrokurl' + ngrokUrl)
console.log('domain' + domain)
console.log('orderId' + orderId)
console.log('itemId' + itemId)
shopifyApiRequest.getRefundCalculationApiCall((itemId, ngrokUrl, domain, orderId));

моя ошибка:

ngrokurl 2undefined
domain2undefined
orderId2undefined
itemId2594597937215
errorError: Invalid URI "undefined/undefined/undefined"

Я ожидаюстандартный ответ.Есть ли что-то очевидное, что мне не хватает?

1 Ответ

0 голосов
/ 18 сентября 2018

В вашем файле index.js вы вызываете метод getRefundCalculationApiCall с двумя наборами круглых скобок вокруг аргументов:

shopifyApiRequest.getRefundCalculationApiCall((itemId, ngrokUrl, domain, orderId));

Это должно быть написано только с одним набором скобок вокруг аргументов:

shopifyApiRequest.getRefundCalculationApiCall(itemId, ngrokUrl, domain, orderId);

Дополнительный набор скобок объединяет все четыре аргумента в один, а затем передает его в качестве аргумента itemId. В итоге вы печатаете значение orderId в операторе console.log('itemId2' + itemId). Три других аргумента игнорируются и поэтому не определены. Вот простой пример:

function test(arg1, arg2, arg3, arg4) {
  console.log('arg1: ' + arg1);
  console.log('arg2: ' + arg2);
  console.log('arg3: ' + arg3);
  console.log('arg4: ' + arg4);
}

console.log('Individual arguments:\n');
test('one', 'two', 'three', 'four');

console.log('Grouped arguments:\n');
test(('one', 'two', 'three', 'four'));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...