Update validate.js

This commit is contained in:
Aleksandr Statciuk 2022-04-09 16:22:05 +03:00
parent 67d7b98f2f
commit 95cd92015b

View file

@ -83,6 +83,10 @@ async function main() {
for (const [i, row] of rows.entries()) {
fileErrors = fileErrors.concat(validateSubdivisionCountry(row, i))
}
} else if (filename === 'regions') {
for (const [i, row] of rows.entries()) {
fileErrors = fileErrors.concat(validateRegionCountries(row, i))
}
}
const schema = Joi.object(schemes[filename])
@ -238,6 +242,20 @@ function validateSubdivisionCountry(row, i) {
return errors
}
function validateRegionCountries(row, i) {
const errors = []
row.countries.forEach(country => {
if (!db.countries[country]) {
errors.push({
line: i + 2,
message: `"${row.code}" has the wrong country "${country}"`
})
}
})
return errors
}
function handleError(message) {
logger.error(chalk.red(`\n${message}`))
process.exit(1)