I have a node service that listens for kafka messages and processes them. I have a controller layer and a model layer. The model layer is responsible for making the database queries and the controller layer handles request. This is how it is defined.
controller.js
kafka.consume((data)=>{
customerModel.save(data.customers);
ordersModel.save(data.orders);
...and a lot of complicated logic here.
paymentsModel.save(data.orders);
})
customerModel.js
exports.save(data) = {
knex("customers").insert(data)...
}
What I want is that, I either the file gets process completely or does not. By processed, I mean I don't want half of the queries only succeed and I'll have inconsistent data. Should the controller layer know anything about knex transactions? what's the best way to approach this?