From b9e6c64bd503752f50ed678b1467620b02f0613c Mon Sep 17 00:00:00 2001 From: Nulo Date: Wed, 11 Sep 2024 22:38:52 -0300 Subject: [PATCH] chequear si hay sucursales en productos.csv que no existen en sucursales.csv --- sepa/sepa-dataset-validator/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sepa/sepa-dataset-validator/index.ts b/sepa/sepa-dataset-validator/index.ts index 3e282c3..de5f8c9 100644 --- a/sepa/sepa-dataset-validator/index.ts +++ b/sepa/sepa-dataset-validator/index.ts @@ -89,6 +89,21 @@ const checkers: Record boolean | string> = { } return false; }, + ["Sucursales mencionadas en productos.csv existen en sucursales.csv"](files) { + const productos = new Set( + files["productos.csv"].data.map((row) => (row as any).id_sucursal) + ); + const sucursales = new Set( + files["sucursales.csv"].data.map((row) => (row as any).id_sucursal) + ); + const missing = [...productos].filter((id) => !sucursales.has(id)); + if (missing.length > 0) { + console.error( + ` Las sucursales ${missing.join(", ")} no existen en sucursales.csv` + ); + } + return missing.length > 0; + }, }; const content = await fs.promises.readdir(dir);