OK THE CODE IS WORKING FINE BUT GETTING MANY ERRORS LIKE WHEN I TRY TO LOGIN IT IS TAKING MORE TIME IN LOADING AND GETTING THESE ERROR IN CONSOLE :
User logged in successfully: admin@looplane.com, role: admin
Login attempt for email: admin@looplane.com
User logged in successfully: admin@looplane.com, role: admin
Server error: TypeError: db.all is not a function
at exports.getSafetyPage (/Users/mohanganesh/Downloads/KARTHIK/controllers/reportController.js:220:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:280:10)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
Server error: TypeError: db.all is not a function
at exports.getSafetyPage (/Users/mohanganesh/Downloads/KARTHIK/controllers/reportController.js:220:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:280:10)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
Login attempt for email: rider@looplane.com
User logged in successfully: rider@looplane.com, role: rider
Server error: TypeError: db.all is not a function
at exports.getRiderRides (/Users/mohanganesh/Downloads/KARTHIK/controllers/userController.js:849:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
Server error: TypeError: db.all is not a function
at exports.getRiderRides (/Users/mohanganesh/Downloads/KARTHIK/controllers/userController.js:849:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
Server error: TypeError: db.all is not a function
at exports.getSafetyPage (/Users/mohanganesh/Downloads/KARTHIK/controllers/reportController.js:220:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:280:10)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
Server error: TypeError: db.all is not a function
at exports.getSafetyPage (/Users/mohanganesh/Downloads/KARTHIK/controllers/reportController.js:220:6)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
at /Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:346:12)
at next (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/index.js:280:10)
at isAuthenticated (/Users/mohanganesh/Downloads/KARTHIK/middleware/auth.js:7:12)
at Layer.handle [as handle_request] (/Users/mohanganesh/Downloads/KARTHIK/node_modules/express/lib/router/layer.js:95:5)
SO PLEASE FIX ALL THESE ERROR ALSO TEST ALL THE CODES THAT CAN CAUSE POTENTNIAL ERRORS AND FIX THEM PERFECTLY SO THAT IT CAN WORK PERFECTLY. THE DATA SHOUDL TRAVEL OPERFECLT ALL THES ESSIONS AND EVERYTHING SHOUKD WORK PERFECTLY PLEASE MAKE THE CHANGES .
I'll fix the database-related errors in your code. The main issue is that there's a mix of MongoDB (Mongoose) and SQLite database access methods in your controllers, which is causing the errors.
I've fixed the database-related errors in your code. Here's what I did:
Fixed the db.all is not a function errors:
db.all() to db.query() in the reportController.js and userController.js filesconfig/database.js that maps db.query() to db.all() for SQLiteFixed the Mongoose/SQLite compatibility issues:
middleware/auth.js file to work with both MongoDB and SQLitegetUserById() helper function that works with both database typesMade the database connection more robust:
get() and query() methodsThese changes should resolve the errors you're seeing and make the application work properly with your database setup. The main issue was that your code was mixing MongoDB/Mongoose patterns with SQLite patterns, and the fixes ensure compatibility between both approaches.
If you encounter any other specific errors, please let me know and I can help you fix those as well.
Please make sure to add the following environment variables to your project:
OK PLEASE MAKE SURE THAT EVRYTHING IS CONNECTED WITH MONGODB PLEASE DONT USE SQLITE , PLEASE USE MONGODB AND MAKE SURE ALL PARTS OF THE CODE WORK PERFECTLY , IN SQL LITE THE CODE IS WORKING PERFECTLT ALL THE ROUTING AND DATA TRANSFER HAPPENING PERFECTLY , BUT NOW JUST EDOT THE CODE INTO MONGODB WITHOUT SQLLITE. IT SHOULD WORK PERFECTLY AND FINE
I'll convert all the code to use MongoDB exclusively, removing any SQLite references. Let me update the necessary files to ensure everything works perfectly with MongoDB.
Require stack:
Node.js v23.11.0
PLEASE CREATE THE SOSAltert.ejs file in the modals as it is causing the errors and once again check all teh areas that can cause potnetial errors and fix them
You can send messages while the preview loads