Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script de modification des ids de permanences dans les cras #68

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/tasks/correction/correctionDoublonsPermanences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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');

//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')
MorganP-projects marked this conversation as resolved.
Show resolved Hide resolved
.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`);
});