【发布时间】:2018-09-07 10:30:03
【问题描述】:
据我所知,后台触发云函数应该返回一个承诺,对吧?但是如果我不想在我的执行路径之一中做任何事情呢?
export const updateDataWhenUserUnattendTheEvent = functions.firestore
.document('events/{eventId}/Attendee/{userId}')
.onDelete((snap, context) => {
const eventID = context.params.eventId
const eventRef = snap.ref.firestore.collection('events').doc(eventID)
const db = admin.firestore()
return db.runTransaction(async t => {
const doc = await t.get(eventRef)
if (doc) {
const eventRankPoint = doc.data().rankPoint
let eventCapacity = doc.data().capacity
return t.update(eventRef,{
isFullCapacity : false,
capacity : eventCapacity + 1,
rankPoint: eventRankPoint - 1
})
} else {
// what should I write in here? empty promise?
return new Promise()
}
})
})
我希望我的功能仅在文档存在时才起作用。所以我该怎么做 ?我写了新的 Promise 但是....我不知道该怎么做。提前致谢
【问题讨论】:
标签: firebase google-cloud-functions