我试图了解如何使用Google云功能正确执行异步操作。它似乎我有语法错误,但我不确定如何解决它。在我添加then()
之前,其余代码能够按预期编译工作。请帮忙
错误:
SyntaxError: Unexpected token )
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
可能出错的区域
if (inviterUID == partnerUID) {
return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
'partnerName': username,
'browniePoints': 0
}).then(() => {
console.log('testing');
})
})
整个代码
exports.checkInviteRequest = functions.firestore
.document('users/{userID}/partnerInviteRequests/{inviterUID}')
.onDelete(invite => {
const uid = invite.params.userID
const inviterUID = invite.params.inviterUID
const deletedInvite = invite.data.previous.data();
const name = deletedInvite.username;
return admin.firestore().collection('users').doc(uid).get().then(profileInfo => {
const partnerUID = profileInfo.data().partnerUID
const username = profileInfo.data().username
if (inviterUID == partnerUID) {
return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
'partnerName': username,
'browniePoints': 0
}).then(() => {
console.log('testing');
})
})
})
});
答案 0 :(得分:1)
您的if
声明中的结束括号过多。特别是这个块的最后一行:
if (inviterUID == partnerUID) {
return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
'partnerName': username,
'browniePoints': 0
}).then(() => {
console.log('testing');
})
})
最后)
不应该在那里。所以:
if (inviterUID == partnerUID) {
return admin.firestore().collection('users').doc(inviterUID).collection('wallet').doc(uid).set({
'partnerName': username,
'browniePoints': 0
}).then(() => {
console.log('testing');
})
}