Hi guys!
Desperately needing some advice.
I am working on an app that in essence acts as a processing tool for hubspot deals. I have forms, 5, that are associated with some database tables.
Since I am inserting user inputs from forms into the database, I am using a mix of SQL and component references, ie {{textInput2.value}} for example.
Since there are about 2 or 3 queriesper form that are being triggered each time that the form submit button is being clicked, I used query_name.trigger() to trigger each insert query.
Problem is that sometimes there are issues along the way (lets say query 1 was triggered and inserted successfully, but query2 fails), then it means that when the user rectifies the issue and clicks submit again, insert starts from the very beginning - causing duplicates etc.
My insert query looks like this:
INSERT INTO company (
company_name,
company_legal_name,
company_country,
company_comment,
company_modif_who,
company_reg_type_id,
company_modif_why
)
VALUES (
{{ numberInput229.value }},
{{ textInput371.value }},
{{ select184.selectedItem.country_id }},
{{ textArea101.value }},
{{ textInput372.value }},
{{ numberInput230.value }},
{{ textArea100.value }}
)
RETURNING company_id;
I've set up an event handler that looks like this:
insert_company_1.trigger({
onSuccess: () => {
console.log("Company Created Successfully!");
refresh_company_query.trigger({
onSuccess: (response) => {
console.log("company refreshed");
button32.setDisabled(true);
formButton55.setDisabled(true);// Disable button after success
},
onFailure: (error) => {
console.error("company_query failed:", error);
alert("company_query failed. Please try again.");
}
});
},
onFailure: (error) => {
console.error("insert_company_1 failed:", error);
alert("Insert company failed. Please try again.");
}
});
My limitation is that I can't use a classic sql rollback function, since the inserts are not purely SQL.
My initial idea was to try and get this restart from the point where it failed and not restart the entire flow of inserts.
Is this a possibility or else is there some advice on how to handle this?
Thanks!