I'm using a soap file to perform simple math accounts, but when I'm going to use the result in my controller to print in JSON, my function returns a "Promise {}" right down here I will leave my function and my controller
const CalcSum = require('../sum');
const calcSum = new CalcSum();
class CalculatorController{
adder (req,res){
const{
value1,
value2,
}= req.body;
const result = calcSum.sum(value1,value2);
console.log(result);
return res.status(200).json({
Response: result
})
}
}
module.exports = CalculatorController;
//end class CalculatorController;
// consolo.log(result) returns Promise {<pending>} in the terminal
//the first class is my controller, next is my function
const soap = require("soap");
const wsdl = "http://www.dneonline.com/calculator.asmx?wsdl";
class CalcSum{
async sum(value1, value2) {
const soapClient = await soap.createClientAsync(wsdl);
await soapClient.Add({ intA: value1, intB: value2 }, (err, result) => {
then(function(result) {
console.log(result);
return result.AddResult;
})
.then(function(result) {
console.log(result);
});
})
}
}
module.exports = CalcSum;
//end class/function CalcSum