I've been working and learning sequelize for a few weeks, at first started with a CRUD using json files, and backend validations with express-validator were working ok, but then migrated to use proper DB using mySQL. So I can make a complete CRUD but when validator jumps in ( either is an empty field or not expected format e.g: isInt() ) I get this error message. The array than should bring after the promise is undefined.
Here is the controller for the create and save:
create:(req, res) => {
let promGames = db.Game.findAll();
let promCreators = db.Creator.findAll();
let promGameGroups = db.Game_group.findAll();
let promCategories = db.Category.findAll();
let promPlatforms = db.Platform.findAll();
let promOsMin = db.Os_min.findAll();
let promOsRec = db.Os_rec.findAll();
let promProcessorMin = db.Processor_min.findAll();
let promProcessorRec = db.Processor_rec.findAll();
let promStorageMin = db.Storage_min.findAll();
let promStorageRec = db.Storage_rec.findAll();
let promGraphicsMin = db.Graphics_min.findAll();
let promGraphicsRec = db.Graphics_rec.findAll();
Promise
.all([promGames, promCreators, promGameGroups, promCategories, promPlatforms, promOsMin, promOsRec,
promProcessorMin, promProcessorRec, promStorageMin, promStorageRec, promGraphicsMin, promGraphicsRec])
.then(([allGames, allCreators, allGameGroups, allCategories, allPlatforms, allOsmin, allOsrec,
allProcessormin, allProcessorec, allStoragemin, allStoragerec, allGraphicsmin, allGraphicsrec]) => {
return res.render(path.join(__dirname, '../views/admin/create'),
{allGames, allCreators, allGameGroups,
allCategories, allPlatforms, allOsmin, allOsrec, allProcessormin,
allProcessorec, allStoragemin, allStoragerec, allGraphicsmin, allGraphicsrec}
)})
.catch(error => res.send(error))
},
save: (req,res) =>{
const resultValidations = validationResult(req)
if(resultValidations.errors.length > 0){
return res.render(path.join(__dirname, '../views/admin/create'), {
errors: resultValidations.mapped(),
oldData: req.body
})};
//CONVIERTE CUALQUIER URL DE YOUTUBE Y EXTRAE EL VIDEO ID (CODIGO DE VIDEO) y los guarda en sendos video_1 y miniatura
url = req.body.video_1
url= url.split(/(shorts\/|vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
id = (url[2] !== undefined) ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0];
video_1 = 'https://www.youtube.com/embed/'+id
miniatura = 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg'
db.Game
.create(
{
title: req.body.title,
one_word_descr: req.body.one_word_descr,
short_descr: req.body.short_descr,
long_descr: req.body.long_descr,
id_game_group: req.body.game_group,
id_category: req.body.category,
id_creator: req.body.creator,
original_price: req.body.original_price,
price_w_discount: req.body.price_w_discount,
discount: req.body.discount,
img_1: req.files.img_1[0].filename,
img_2: req.files.img_2[0].filename,
img_3: req.files.img_3[0].filename,
img_4: req.files.img_4[0].filename,
img_5: req.files.img_5[0].filename,
video_1: 'https://www.youtube.com/embed/'+id,
miniatura : 'https://img.youtube.com/vi/'+id+'/mqdefault.jpg',
launch_date:req.body.launch_date,
id_platforms: req.body.platform,
id_os_min: req.body.os_min,
id_os_rec: req.body.os_rec,
id_processor_min:req.body.processor_min,
id_processor_rec:req.body.processor_rec,
id_storage_min: req.body.storage_min,
id_storage_rec: req.body.storage_rec,
id_graphics_min: req.body.graphics_min,
id_graphics_rec: req.body.graphics_rec,
age: req.body.age
}
)
.then(()=> {
return res.redirect('/admin')})
.catch(error => res.send(error))
},
This is the error message:
But it's not specefically in "allGameGroups" , whichever result of the promise .then(([allGames, allCreators, allGameGroups, allCategories, allPlatforms, allOsmin, allOsrec, allProcessormin, allProcessorec, allStoragemin, allStoragerec, allGraphicsmin, allGraphicsrec]) any of these will result undefined. allGameGroups in this case because is the first one showing in the view. If I replace positions allGameGroups for eg: allStoragemin , this latter is the one undefined.
I discovered that if I "turn off" validations there is no problem, so somehow is related with express-validator. I would really apreciatte some help.

