Skip to content

Commit

Permalink
feat: restaurer données stagiaires
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Perrin committed Jul 10, 2024
1 parent 69e9068 commit 8d663fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/jobs/import/stagiaires/tasks/importStagiaires.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const validateStagiaire = require('./utils/validateStagiaire');
const shouldBeImported = require('./utils/shouldBeImported');
const hasNotBeenImported = require('./utils/hasNotBeenImported');
const organismeResponsableAbsent = require('./utils/organismeResponsableAbsent');
const individuAbsent = require('./utils/individuAbsent');
const { transformObject, writeObject, ignoreFirstLine, pipeline, parseCSV } = require('../../../../core/utils/stream-utils');
const { getCampaignDate, getCampaignName, sanitizeCsvLine } = require('./utils/utils');

Expand Down Expand Up @@ -48,12 +49,23 @@ module.exports = async (db, logger, file, handler, filters = {}, options = {}) =
{refreshKey: stagiaire.refreshKey},
{
$set: {
"individu": stagiaire.individu,
"formation.action.organisme_responsable": stagiaire.formation.action.organisme_responsable
}
}
);
stats.imported++;
logger.debug('Organisme responsable updated');
} else if (shouldStagiaireBeImported && await individuAbsent(db, stagiaire)) {
await db.collection('stagiaires').updateOne(
{refreshKey: stagiaire.refreshKey},
{
$set: {
"individu": stagiaire.individu
}
}
);
stats.imported++;
} else {
stats.ignored++;
logger.debug('Stagiaire ignored', stagiaire, {});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = async (db, stagiaire) => {
let nbStagiaires = await db.collection('stagiaires').countDocuments({
refreshKey: stagiaire.refreshKey,
individu: { $exists: false }
});
return nbStagiaires === 1;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe(__filename, withMongoDB(({ getTestDatabase, getComponents, getTestFile,
let { regions } = await getComponents();

await importStagiaires(db, logger, getTestFile('stagiaires-pe.csv'), poleEmploiCSVHandler(db, regions));

await db.collection('stagiaires').updateOne({ 'individu.nom': 'MARTINADO' }, { $unset: { individu: 1 } });
await importStagiaires(db, logger, getTestFile('stagiaires-pe.csv'), poleEmploiCSVHandler(db, regions));

const filters = { all: true };
await countStagiaires(db, logger, filters);

Expand Down Expand Up @@ -84,7 +88,9 @@ describe(__filename, withMongoDB(({ getTestDatabase, getComponents, getTestFile,
},
},
});

let results_siret_0 = await db.collection('stagiaires').find({ 'individu.nom': 'MARTINADO' }).toArray();
assert.strictEqual("MARTINADO", results_siret_0[0].individu.nom);
assert.strictEqual("82436343601230", results_siret_0[0].formation.action.organisme_formateur.siret);
assert.strictEqual("ANOTEA 0", results_siret_0[0].formation.action.organisme_formateur.raison_sociale);
});
Expand Down

0 comments on commit 8d663fc

Please sign in to comment.