Вы не создаете свое собственное обещание (это явный антипаттерн конструкции обещания ); вместо этого объедините существующие обещания вместе и верните результат.
Вот один из способов сделать это, см. ***
комментарии:
sentTest: (message) => {
let mongoRecord = null;
let asResponse;
// *** Return the result of the chain
return getMongoField('terminals', {'attributes.XYZ': 'ABC'})
.then(function (docs) {
// *** Return the promise for the next operation
return ts.sendFirstMessage(docs.attributes.sno, docs, docs.attributes.value)
.then(() => {
// *** Return the promise for the next operation
// This has to be nested because it uses `docs`
return ts.SendSecondMessage(docs.attributes.sno, 'Test', docs, message);
});
})
},
или
sentTest: (message) => {
let asResponse;
// *** Return the result of the chain
return getMongoField('terminals', {'attributes.XYZ': 'ABC'})
.then(docs => {
// *** Return the promise for the next operation
return ts.sendFirstMessage(docs.attributes.sno, docs, docs.attributes.value)
// *** Settle the promise from `then` with `docs` so the next handler can see it
.then(() => docs);
})
.then(docs => {
// *** Return the promise for the next operation
return ts.SendSecondMessage(docs.attributes.sno, 'Test', docs, message);
});
},