I am fetching data from a node from Firebase Database and then after doing some calculations I am updating it.
I am using Firebase SDK in node js to perform this task.
Here is the code:
app.get("/setBookedSpots", function (request, response) {
console.log("booked spots called");
var verifierEmail = request.query.verifierEmail;
var toBeBookedSpot = request.query.bookSpot;
console.log(toBeBookedSpot);
admin.auth().getUserByEmail(verifierEmail)
.then(function (userRecord) {
console.log("Successfully fetched user data:", userRecord.toJSON());
var verifierId = userRecord.uid;
var refToUserInformation = db.ref("user/" + verifierId);
refToUserInformation.child("Society_Name").on("value", function (snapshot) {
console.log(snapshot.val());
var SocietyName = snapshot.val();
refToSocietyBookingStatus = db.ref("Societies/" + SocietyName + "/Society_Parking_Details/Society_Parking_Status");
refToSocietyBookingStatus.child("Booked_Spots").on("value", function (snapshot) {
var Booked_Spots = snapshot.val();
console.log(Booked_Spots);
console.log("to be booked spot", toBeBookedSpot);
Booked_Spots = Booked_Spots.toString() + "," + toBeBookedSpot;
console.log("after booked spot", Booked_Spots);
refToSocietyBookingStatus.update({
"Booked_Spots": Booked_Spots
})
response.send({ "msg": "success" });
})
})
});
});
I am getting the booked spots and the updating them based on the request parameter.
When I hit it, it goes in infinite callback. What I mean to say is it keeps on appending recursively as there is no loop which makes it to crash.
I tried using a different variable for the database reference so that it might not be calling the parent event again but still the same problem.
Here is the service call url:
http://localhost:8080/[email protected]&bookSpot=A7