Currently, I am utilizing a Firebase function to write data into the database. This function is triggered by an HTTP call, specifically a POST request. While I have successfully saved the data to the database, I have encountered difficulty returning the data in the proper format. The error message I'm receiving is as follows:
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;
}
}));