Use trigger events of postgres for updating collections and book status
Refactor the way we update the status of books and Collections.
Books and Collections statuses were calculated from the status of each chapter or book that belong to them.
The update function is here : https://gitlab.coko.foundation/ncbi/ncbi/-/blob/develop/server/models/book/book.js#L526
We are calling this function every time we have an update at the book of chapters, there is an easier way of doing this by writing a postgresql trigger event on every update of book or chapter and by that the postgres function can do the update for the book status.
-
Remove the function that is responsible now for updating the book status. Remove any call that we do that function. -
Create a postgresql trigger event and a new function that hanldes the status update of the book