From 9a2cfb45f0d9d846c8654c4de18505b26a7fea32 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 9 Apr 2022 16:05:00 +0300 Subject: [PATCH] Update validate.js --- scripts/db/validate.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/db/validate.js b/scripts/db/validate.js index 17c38a4f..7f39d37d 100644 --- a/scripts/db/validate.js +++ b/scripts/db/validate.js @@ -65,10 +65,11 @@ async function main() { fileErrors = fileErrors.concat(findDuplicatesById(rows)) 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 validateChannelLanguages(row, i)) fileErrors = fileErrors.concat(await validateChannelCountry(row, i)) - fileErrors = fileErrors.concat(await validateChannelSubdivision(row, i)) } } else if (filename === 'blocklist') { for (const [i, row] of rows.entries()) { @@ -160,6 +161,25 @@ async function validateChannelSubdivision(row, i) { 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) { const errors = [] row.languages.forEach(language => {