Update validate.js

This commit is contained in:
Aleksandr Statciuk 2022-04-09 16:05:00 +03:00
parent 9f925606bd
commit 9a2cfb45f0

View file

@ -65,10 +65,11 @@ async function main() {
fileErrors = fileErrors.concat(findDuplicatesById(rows)) fileErrors = fileErrors.concat(findDuplicatesById(rows))
for (const [i, row] of rows.entries()) { for (const [i, row] of rows.entries()) {
fileErrors = fileErrors.concat(await validateChannelBroadcastArea(row, i))
fileErrors = fileErrors.concat(await validateChannelSubdivision(row, i))
fileErrors = fileErrors.concat(await validateChannelCategories(row, i)) fileErrors = fileErrors.concat(await validateChannelCategories(row, i))
fileErrors = fileErrors.concat(await validateChannelLanguages(row, i)) fileErrors = fileErrors.concat(await validateChannelLanguages(row, i))
fileErrors = fileErrors.concat(await validateChannelCountry(row, i)) fileErrors = fileErrors.concat(await validateChannelCountry(row, i))
fileErrors = fileErrors.concat(await validateChannelSubdivision(row, i))
} }
} else if (filename === 'blocklist') { } else if (filename === 'blocklist') {
for (const [i, row] of rows.entries()) { for (const [i, row] of rows.entries()) {
@ -160,6 +161,25 @@ async function validateChannelSubdivision(row, i) {
return errors return errors
} }
async function validateChannelBroadcastArea(row, i) {
const errors = []
row.broadcast_area.forEach(area => {
const [type, code] = area.split('/')
if (
(type === 'r' && !db.regions[code]) ||
(type === 'c' && !db.countries[code]) ||
(type === 's' && !db.subdivisions[code])
) {
errors.push({
line: i + 2,
message: `"${row.id}" has the wrong broadcast_area "${area}"`
})
}
})
return errors
}
async function validateChannelLanguages(row, i) { async function validateChannelLanguages(row, i) {
const errors = [] const errors = []
row.languages.forEach(language => { row.languages.forEach(language => {