I'm having trouble building an Express API in TypeScript using Node.js. I am new to Express and I have been learning Node, JavaScript, and TypeScript since 2022, so I apologize if the question is not too complex. The issue I'm facing is trying to build a class Controller that handles the necessary instructions for every route in my Express router. I am passing a DAO through the constructor that I have built to access the Firebase Firestore database. However, when I instantiate the object and try to run it, it gives me a "cannot read properties of undefined" error. Even though I found a solution using a closure, I want to learn how to do this using classes. Here is the code of the DAO:
// Code for the DAO class goes here...
And this is the code for the Controller class:
// Code for the Controller class goes here...
Thanks for your time. I'm trying to learn this beautiful world of backend development. I have tried various solutions to my issue, such as calling the constructor outside the class and passing the constant to the constructor, instantiating the DAO object as a parameter, and even calling the DAO constructor in a global variable and defining the properties. However, the only solution I found for my issue is transforming the class into a closure function and calling the constructor within the closure.
// Error message and stack trace about 'dbManager' being undefined...
Routes
// Code for the routes definition and calling the readData method...