@@ -4,9 +4,11 @@ const JsDocs = require('./jsdocFolder');
44const lineageManipulation = require ( './lineage-manipulation' ) ;
55const LineageConstraints = require ( './lineage-constraints' ) ;
66const { trace, info } = require ( '../log' ) ;
7+ const requestsApi = require ( '../../lib/api' ) ;
78
89async function moveHierarchy ( db , options , sourceIds , destinationId ) {
910 JsDocs . prepareFolder ( options ) ;
11+ const api = requestsApi ( ) ;
1012 trace ( `Fetching contact details: ${ destinationId } ` ) ;
1113 const constraints = await LineageConstraints ( db , options ) ;
1214 const destinationDoc = await DataSource . getContact ( db , destinationId ) ;
@@ -44,7 +46,7 @@ async function moveHierarchy(db, options, sourceIds, destinationId) {
4446
4547 minifyLineageAndWriteToDisk ( options , [ ...updatedDescendants , ...updatedAncestors ] ) ;
4648
47- const movedReportsCount = await updateReports ( db , options , moveContext ) ;
49+ const movedReportsCount = await updateReports ( api , options , moveContext ) ;
4850 trace ( `${ movedReportsCount } report(s) created by these affected contact(s) will be updated` ) ;
4951
5052 affectedContactCount += updatedDescendants . length + updatedAncestors . length ;
@@ -56,15 +58,15 @@ async function moveHierarchy(db, options, sourceIds, destinationId) {
5658 info ( `Staged changes to lineage information for ${ affectedContactCount } contact(s) and ${ affectedReportCount } report(s).` ) ;
5759}
5860
59- async function updateReports ( db , options , moveContext ) {
61+ async function updateReports ( api , options , moveContext ) {
6062 const descendantIds = moveContext . descendantsAndSelf . map ( contact => contact . _id ) ;
6163
6264 let skip = 0 ;
6365 let reportDocsBatch ;
6466 do {
6567 info ( `Processing ${ skip } to ${ skip + DataSource . BATCH_SIZE } report docs` ) ;
6668 const createdAtId = options . merge && moveContext . sourceId ;
67- reportDocsBatch = await DataSource . getReportsForContacts ( db , descendantIds , createdAtId , skip ) ;
69+ reportDocsBatch = await DataSource . getReportsForContacts ( api , descendantIds , createdAtId , skip ) ;
6870
6971 const lineageUpdates = replaceLineageOfReportCreator ( reportDocsBatch , moveContext ) ;
7072 const reassignUpdates = reassignReports ( reportDocsBatch , moveContext ) ;
0 commit comments