From 9e04b389553fe321765db7c7f97144908b0ab186 Mon Sep 17 00:00:00 2001 From: morgan Date: Thu, 14 Sep 2023 17:44:43 +0200 Subject: [PATCH 1/2] script de modification des ids de permanences dans les cras --- .../correctionDoublonsPermanences.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tasks/correction/correctionDoublonsPermanences.js diff --git a/src/tasks/correction/correctionDoublonsPermanences.js b/src/tasks/correction/correctionDoublonsPermanences.js new file mode 100644 index 0000000..b27087a --- /dev/null +++ b/src/tasks/correction/correctionDoublonsPermanences.js @@ -0,0 +1,41 @@ +#!/usr/bin/env node +'use strict'; +const csv = require('csv-parser'); +const fs = require('fs'); +const { encrypt } = require('../../utils/encrypt'); +const { execute } = require('../utils'); + +const updateCraWithIdPermanence = dbDatalake => async (id, ids) => await dbDatalake.collection('cras').updateMany( + { 'permanenceId': { '$in': ids } }, + { 'permanenceId': id } +); + +execute(__filename, async ({ logger, dbDatalake }) => { + + const permanences = []; + const promises = []; + let nbMaj = 0; + + logger.info('Modification des ids suite à la fusion des doublons de permanences'); + + fs.createReadStream('data/imports/permanences-doublons.csv') + .pipe(csv({ separator: ';' })) + .on('data', data => permanences.push(data)) + .on('end', () => { + permanences.forEach(permanence => { + promises.push(new Promise(async resolve => { + const id = encrypt(permanence.idPermanence.toString()); + const ids = []; + permanence.doublons.split(',').forEach(id => { + ids.push(encrypt(id.toString())); + }); + await updateCraWithIdPermanence(dbDatalake)(id, ids); + nbMaj++; + resolve(); + })); + }); + Promise.all(promises); + }); + + logger.info(`${nbMaj} CRAs mis à jour`); +}); From d7fd0f8ffa6857b4a385e942765a2135ab255cd4 Mon Sep 17 00:00:00 2001 From: morgan Date: Tue, 19 Sep 2023 12:04:46 +0200 Subject: [PATCH 2/2] =?UTF-8?q?ajout=20de=20l'ent=C3=AAte=20des=20colonnes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tasks/correction/correctionDoublonsPermanences.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tasks/correction/correctionDoublonsPermanences.js b/src/tasks/correction/correctionDoublonsPermanences.js index b27087a..b5aea9e 100644 --- a/src/tasks/correction/correctionDoublonsPermanences.js +++ b/src/tasks/correction/correctionDoublonsPermanences.js @@ -18,6 +18,8 @@ execute(__filename, async ({ logger, dbDatalake }) => { logger.info('Modification des ids suite à la fusion des doublons de permanences'); + //eslint-disable-next-line max-len + //idPermanence|estStructure|nomEnseigne|numeroTelephone|email|siteWeb|siret|adresse|location|horaires|typeAcces|conseillers|lieuPrincipalPour|conseillersItinerants|structure|updatedAt|updatedBy|doublons fs.createReadStream('data/imports/permanences-doublons.csv') .pipe(csv({ separator: ';' })) .on('data', data => permanences.push(data)) @@ -36,6 +38,6 @@ execute(__filename, async ({ logger, dbDatalake }) => { }); Promise.all(promises); }); - + logger.info(`${nbMaj} CRAs mis à jour`); });