As I dive into the world of Sequelize, I've hit a roadblock. In my attempt to connect my controller, route, model, and other components, I encountered an error when trying to access my route (localhost:3000/api/carousel):
TypeError: Cannot read properties of undefined (reading 'findAll')
at getAllCarouselItems (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\controllers\carousel-item_controller.js:6:47)
at Layer.handle [as handle_request] (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\index.js:284:15
at Function.process_params (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\index.js:346:12)
at next (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\index.js:280:10)
at Function.handle (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\index.js:175:3)
at router (C:\Users\theob\OneDrive\Documents\DEV\le_burguignon\back\node_modules\express\lib\router\index.js:47:12)
In my controller, the findAll method is not working as expected:
const CarouselItem = require('../models/carousel-item');
const db = require('../config/sequelize');
async function getAllCarouselItems(req, res) {
try {
const carouselItems = await db.CarouselItem.findAll();
res.json(carouselItems);
} catch (err) {
console.error(err);
res.status(500).json({ message: 'Server Error' });
}
}
module.exports = { getAllCarouselItems };
I'm wondering if there's something crucial that I might have overlooked.
I've attempted using console logs, researching the errors online, and even seeking assistance from chatbots, but as a novice in this technology, I often feel lost and uncertain about where to focus my attention.