I have a problem with Cloud Functions.
I am making a reservation system. When an admin accepts a reservation, I make this call on the client:
reservationRef.update({
handled: true,
lastHandledBy: AUTH.currentUser.uid,
timestamp: TIMESTAMP
})
Here is how the whole reservation looks like:
roomId: number
address: string
name: string
tel: string
message: string
email: string
from: number
to: number
timestamp: date
lastHandledBy: string
handled: boolean
adults: number
children: number
In Cloud Functions, I have a function that triggers when the reservation is updated, so I can send a confirmation e-mail to the user. It looks like this:
exports.reservationChanged = reservationRef
.onUpdate(({before, after}, {params: {reservationId}}) => {
before = before.data()
after = after.data()
// Reservation accepted
if (!before.handled && after.handled) {
return email.reservationAccepted(reservationId, after)
}
}
For some reason though, it is triggered twice and sends two e-mails, and I don't know why. I update the reservation with a simple .update()
What did I do wrong?
Thanks