The second cloudFunction doesnt even get called (The one on TipCreated Table). I dont know what the error is:
Moralis.Cloud.afterSave("QuestionCreated", async function(request) {
const confirmed = request.object.get("confirmed");
console.log(request.object);
if (confirmed) {
const array = [number];
const Question = Moralis.Object.extend("QuestionTipsSum");
const question = new Question();
question.set("questionId", request.object.get("questionId"));
question.set("sessionId", request.object.get("sessionId"));
question.set("value", parseInt(request.object.get("value")));
question.set("createdBy", request.object.get("createdBy"));
question.set("createdAt", request.object.get("createdAt"));
question.set("link", request.object.get("link"));
question.set("tipIds", array);
question.save().then((question) => {
// Execute any logic that should take place after the object is saved.
console.log('New object created with objectId: ' + question.id);
}, (error) => {
// Execute any logic that should take place if the save fails.
// error is a Moralis.Error with an error code and message.
console.log('Failed to create new object, with error code: ' + error.message);
});
}
});
Moralis.Cloud.afterSave("TipCreated", async function(request) {
const query = new Moralis.Query("QuestionTipsSum");
query.equalTo("questionId", request.object.get("questionId"));
query.find({
success:function(list) {
let question = list[0];
let oldValue = question.get("value");
let tipIds = question.get("tipsIds");
console.log("old Value", oldValue);
let newValue= oldValue + parseInt(request.object.get("value"));
tipIds.push(request.object.get("tipId"));
question.set("value", newValue);
question.set("tipIds", tipIds);
question.save().then((question) => {
// Execute any logic that should take place after the object is saved.
console.log('New object created with objectId: ' + question.id);
}, (error) => {
// Execute any logic that should take place if the save fails.
// error is a Moralis.Error with an error code and message.
console.log('Failed to create new object, with error code: ' + error.message);
});
}
});
});