I do appreciate this question has been answered in a few places. I'm new to Firebase cloud functions (and learning TS), so I'd just like to see the solution in my own context to fully understand the issue here.
My index.ts:
exports.OnPlanCreate = functions.database
.ref(`users/{uid}/plans/{key}`)
.onCreate((snapshot, context) => {
const user: string = context.params.uid
const fBaseKey: string = context.params.key
// const plan: any = snapshot.val()
console.log(`New plan created with key ${fBaseKey}for user ${user}`)
// Update plan object key with Firebase generated DB key
snapshot.ref.update({ key: fBaseKey })
.then(() => {
console.log('Plan key auto updated successfully!')
})
.catch((e) => {
console.error(e)
})
})
Gives the warning: "Function returned undefined, expected Promise or value"
I'd appreciate an explanation that helps me to understand the correct pattern to use in future :)
Thanks so much!