router.ts
import UserController from './controllers/UserController'
router.get( '/users', UserController.getAll);
Controller.ts
class Controller {
async _getAll() {
return {user: "test"}
}
}
export default Controller
UserController.ts
import { NextFunction, Request, Response } from "express"
import Controller from "./Controller";
class UserController extends Controller {
async getAll (req: Request, res: Response, next: NextFunction) {
const response = await this._getAll()
return res.status( 200 ).json( response )
}
}
export default new UserController( );
My main question is i want to use get function other controllers extends from Controller.ts but getting this error:
TypeError: Cannot read properties of undefined (reading '_getAll') at /private/var/www/project/src/controllers/UserController.ts:8:37