Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Product.findById is not a function #4364

Closed
Adepusrikanth9666 opened this issue Apr 25, 2024 · 1 comment
Closed

TypeError: Product.findById is not a function #4364

Adepusrikanth9666 opened this issue Apr 25, 2024 · 1 comment
Labels

Comments

@Adepusrikanth9666
Copy link

HIello everyone could u please help me in this issue im facing..

below i smy code:

`exports.getEditProduct = (req, res, next) => {
const editMode = req.query.edit;
if (!editMode) {
return res.redirect('/');
}
const prodId = req.params.productId;
Product.findById(prodId).then(product=> {
if (!product) {
return res.redirect('/');
}
res.render('admin/edit-product', {
pageTitle: 'Edit Product',
path: '/admin/edit-product',
editing: editMode,
product: product
})
}).catch(err=>console.log(err))

}
`

And the Error which im getting is
**TypeError: Product.findById is not a function** at exports.getProduct (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\controllers\shop.js:24:11) at Layer.handle [as handle_request] (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\layer.js:95:5) at next (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\route.js:149:13) at Route.dispatch (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\route.js:119:3) at Layer.handle [as handle_request] (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\layer.js:95:5) at D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\index.js:284:15 at param (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\index.js:365:14) at param (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\index.js:376:14) at Function.process_params (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\index.js:421:3) at next (D:\Srikanth\Projects\Udemy\Node\connecting-our-app\node_modules\express\lib\router\index.js:280:10)

@Adepusrikanth9666
Copy link
Author

Issue is Sloved by using this code snippit
Product.findAll({where:{id:prodId}})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant