From 34d05d513ffd51ea3edeffa47bc6f5ce7924327c Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 9 Apr 2022 04:02:02 +0300 Subject: [PATCH] Update validate.js --- scripts/db/validate.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/db/validate.js b/scripts/db/validate.js index f1f996c1..803c91b7 100644 --- a/scripts/db/validate.js +++ b/scripts/db/validate.js @@ -53,6 +53,25 @@ async function main() { } fileErrors = fileErrors.concat(findDuplicatesById(data)) + + let categories = await csv.fromFile('data/categories.csv').catch(err => { + logger.error(chalk.red(`\nError: ${err.message}`)) + process.exit(1) + }) + categories = categories.map(c => c.id) + + data.forEach((row, i) => { + if ( + categories.length && + row.categories.length && + intersection(categories, row.categories).length !== row.categories.length + ) { + fileErrors.push({ + line: i + 2, + message: `"${row.id}" has the wrong categories "${row.categories.join(';')}"` + }) + } + }) } else if (filename === 'blocklist') { let channels = await csv.fromFile('data/channels.csv').catch(err => { logger.error(chalk.red(`\nError: ${err.message}`)) @@ -118,3 +137,9 @@ function findDuplicatesById(data) { return errors } + +function intersection(array1, array2) { + return array1.filter(function (n) { + return array2.indexOf(n) !== -1 + }) +}