` exports.start = async (req, res) => {
function saveLanguajes() {
try{
let errors = {};
Object.keys(languages).map(function (key, index) {
let languageObject = {
abbreviation: key,
name: languages[key].name,
native_name: languages[key].nativeName
};
language = new Language(languageObject);
language.save({ runValidators: true }, async (err, languageDB) => {
if(err){
errors[key] = [];
if(err.errors.hasOwnProperty('abbreviation')){
errors[key].push(err.errors.abbreviation.properties.message);
} else if(err.errors.hasOwnProperty('name')){
errors[key].push(err.errors.name.properties.message);
} else if(err.errors.hasOwnProperty('native_name')){
errors[key].push(err.errors.native_name.properties.message);
console.log(errors);
}
}
});
});
if(errors){
console.log(errors);
return res.status(400).json({ ok: false, errors: errors });
}else{
return res.status(200).json({ ok: true });
}
}catch(errors){
console.log(errors);
return res.status(400).json({ ok: false, errors });
}
}
await saveLanguajes();
} `
exports.start = async (req, res) => {
function saveLanguajes() {
try{
let errors = {};
Object.keys(languages).map(function (key, index) {
let languageObject = {
abbreviation: key,
name: languages[key].name,
native_name: languages[key].nativeName
};
language = new Language(languageObject);
language.save({ runValidators: true }, async (err, languageDB) => {
if(err){
errors[key] = [];
if(err.errors.hasOwnProperty('abbreviation')){
errors[key].push(err.errors.abbreviation.properties.message);
} else if(err.errors.hasOwnProperty('name')){
errors[key].push(err.errors.name.properties.message);
} else if(err.errors.hasOwnProperty('native_name')){
errors[key].push(err.errors.native_name.properties.message);
console.log(errors);
}
}
});
});
if(errors){
console.log(errors);
return res.status(400).json({ ok: false, errors: errors });
}else{
return res.status(200).json({ ok: true });
}
}catch(errors){
console.log(errors);
return res.status(400).json({ ok: false, errors });
}
}
await saveLanguajes();
}