Olá estou com o seguinte error, e não faço ideia por qual motivo:
TypeError: Cannot read property 'create' of undefined at UsersController.create (C:\Users\SpiriT\Documents\ProjetoWEB\backend\src\controllers\users.js:24:18) at C:\Users\SpiriT\Documents\ProjetoWEB\backend\src\routes\users.js:22:18
nesses 2 arquivos:
controllers\users.js :
const HttpStatus = require('http-status');
class UsersController {
constructor(modelUser){
this.Users = modelUser;
}
getAll(){
return this.Users
.findAll({})
.then(rs => rs)
.catch(e => e);
}
getById(params){
return this.Users
.findOne({where:params})
.then(rs=>rs)
.catch(e=>e);
}
create(data){
return this.Users
.create(data)
.then(rs=>rs)
.catch(e=>e);
}
update(data,params){
return this.Users
.update(data, {where: params})
.then(rs=>rs)
.catch(e=>e);
}
delete(params){
return this.Users
.destroy({where:params})
.then(rs=>rs)
.catch(e=>e);
}
}
module.exports = UsersController;
routes users.js:
const UsersController = require('../controllers/users')
module.exports = (app) => {
const usersController = new UsersController(app.datasource.models.users);
app.route('/users')
.get((req,res)=>{
usersController
.getAll()
.then(data => {
res.json(data);
})
.catch(error=>{
console.log(error);
res.status(400);
});
})
.post((req,res)=>{
usersController
.create(req.body)
.then(rs=>{
res.json(rs);
res.status(201);
})
.catch(error=>{
console.log(error)
res.status(422);
});
});
};
