I am using firebase function to write the data into the database. The function I am using is triggered by HTTP call (only POST). I was able to save the data to the database, however, couldn't return the data in proper format. I am getting, the following error
TypeError: snapshot.val is not a function
export const saveOrder = functions.https.onRequest(((request, response) => {
if (request.method == "POST") {
const data = JSON.stringify(request.body);
let jsonData = data.replace(/\r?\n\t?/g, '');
let object = {order: JSON.parse(jsonData), status: "pending"};
return admin.database()
.ref("orders")
.push(object)
.then(function (snapshot) {
return response.send(200, snapshot.val());
});
} else {
response.contentType("application/json");
response.status(400).send('{"message":"Invalid method"}');
return;
}
}));