Tentando rodar o codigo obtive o seguinte erro :
ReferenceError: updatedData is not defined
at PessoaServices.updateRegister (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\src\services\Services.js:13:67)
at PessoaController.updateData (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\src\controllers\Controller.js:19:50)
at D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\src\routes\pessoasRoute.js:10:59
at Layer.handle [as handle_request] (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\router\layer.js:95:5)
at next (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\noejs-express-sequelize\node_modules\express\lib\router\layer.js:95:5)
at D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\router\inde\express\lib\router\index.js:284:15
at param (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\routmodules\express\lib\router\index.js:365:14)
at param (D:\aprogramação\estudos\js\alura\nodejs-express-sequelize\node_modules\express\lib\routmodules\express\lib\router\index.js:376:14)
Fala que não foi declarado, porem foi no arquivo Controller.js ...
Segue abaixo os arquivos
Controller.js
class Controller {
constructor (entityService){
this.entityService = entityService;
}
async getAll(req, res) {
try {
const listOfPeople = await this.entityService.getAllRegisters();
return res.status(200).json(listOfPeople);
} catch (err) {
//erro
}
}
async updateData(req, res) {
const { id } = req.params;
const updatedData = req.body;
try {
const isUpdated = await this.entityService.updateRegister(updatedData, Number(id));
if (!isUpdated) {
return res.status(400).json( { message: 'data was not updated'} );
}
return res.status(200).json( { message: `id : ${id} updated!`} );
} catch (err) {
console.error(err);
}
}
}
module.exports = Controller;
Services.js
const dataSource = require('../models');
class Services {
constructor(modelName) {
this.model = modelName;
}
async getAllRegisters() {
return dataSource[this.model].findAll();
}
async updateRegister() {
const listOfUpdatedData = await dataSource[this.model].update(updatedData, {
where: {id: id}
});
console.log('service');
return true;
}
}
module.exports = Services;