1
파이어베이스에 실시간 데이터베이스 트리거를 사용하는 클라우드 기능을 작성하고 있습니다. 그것은 onWrite
을 발생시킨 다음 Promises
을 사용하여 일련의 명령을 실행해야합니다.파이어베이스 기능이 필요합니다. 약속 또는 가치
약속을 사용할 때 코드가 실행되고 약속을 지킬 때 신뢰할 수 없게됩니다. 필요한 곳마다 값을 반환하고
Function returned undefined, expected Promise or value
아직 나는이 메시지와 함께 결국 : 그러나, 나는 항상 로그에이를 얻을. 내 코드는 다음과 같습니다.
exports.sendQuotationToCustomer = functions.database.ref('/company/{companyId}/quotations/{quotationId}').onWrite((event) => {
const companyId = event.params.companyId;
console.log('Direct Generate');
const root = event.data.ref.root;
return root.child(`company/${companyId}/profile`).once('value')
.then((profileSnap) => {
console.log('1/Step');
const profile = profileSnap.val();
const docDefinition = helpers.createDocumentDefinition(profile, quotationData);
return docDefinition;
})
.then((result) => {
console.log('2/Step');
// Perform some manipulation over result. But meanwhile:
return result;
})
.catch((err) => {
console.log(`Failed with error info: ${err}`);
});
});
여기에 무슨 문제가 있습니까?
정확히'docDefinition'이란 무엇입니까? –
안녕하세요 @DougStevenson, docDefinition은이 작업이 완료되면 2 단계에서 사용할 PDF 생성 용입니다. 나는 샘플 코드를 다음과 같이 작성했다 :'https : // pastebin.com/Ubf10xqK' –
또한, 당신이 약속을 묶을 때 "믿을 수 없게된다"고 말할 때 당신은 무엇을 의미합니까? 2 단계에서 비동기 작업을하고 있습니까? –