-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This adds new action cht merge-contacts. The change proposes to: Move the code for move-contacts into a library lib/hierarchy-operations with interfaces move and merge Parameterize the move-contacts code changing logic for: input validation, deletes the top-level contact, changes how lineages are updated, and adds report reassignment. All else remains unaltered. Handles reports and contacts only. Unclear what other doc types I should be worried about.
- Loading branch information
1 parent
da017f9
commit 006554c
Showing
20 changed files
with
1,890 additions
and
1,371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ upload-docs.*.log.json | |
/.vscode/ | ||
/.idea/ | ||
/.settings/ | ||
/json_docs/ | ||
*.swp | ||
coverage | ||
.nyc_output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const minimist = require('minimist'); | ||
const path = require('path'); | ||
|
||
const environment = require('../lib/environment'); | ||
const pouch = require('../lib/db'); | ||
const { info } = require('../lib/log'); | ||
|
||
const HierarchyOperations = require('../lib/hierarchy-operations'); | ||
|
||
module.exports = { | ||
requiresInstance: true, | ||
execute: () => { | ||
const args = parseExtraArgs(environment.pathToProject, environment.extraArgs); | ||
const db = pouch(); | ||
const options = { | ||
docDirectoryPath: args.docDirectoryPath, | ||
force: args.force, | ||
}; | ||
return HierarchyOperations(db, options).merge(args.sourceIds, args.destinationId); | ||
} | ||
}; | ||
|
||
// Parses extraArgs and asserts if required parameters are not present | ||
const parseExtraArgs = (projectDir, extraArgs = []) => { | ||
const args = minimist(extraArgs, { boolean: true }); | ||
|
||
const sourceIds = (args.sources || args.source || '') | ||
.split(',') | ||
.filter(Boolean); | ||
|
||
if (!args.destination) { | ||
usage(); | ||
throw Error(`Action "merge-contacts" is missing required contact ID ${bold('--destination')}. Other contacts will be merged into this contact.`); | ||
} | ||
|
||
if (sourceIds.length === 0) { | ||
usage(); | ||
throw Error(`Action "merge-contacts" is missing required contact ID(s) ${bold('--sources')}. These contacts will be merged into the contact specified by ${bold('--destination')}`); | ||
} | ||
|
||
return { | ||
destinationId: args.destination, | ||
sourceIds, | ||
docDirectoryPath: path.resolve(projectDir, args.docDirectoryPath || 'json_docs'), | ||
force: !!args.force, | ||
}; | ||
}; | ||
|
||
const bold = text => `\x1b[1m${text}\x1b[0m`; | ||
const usage = () => { | ||
info(` | ||
${bold('cht-conf\'s merge-contacts action')} | ||
When combined with 'upload-docs' this action moves all of the contacts and reports under ${bold('sources')} to be under ${bold('destination')}. | ||
The top-level ${bold('source contact(s)')} are deleted and no data from this document is merged or preserved. | ||
${bold('USAGE')} | ||
cht --local merge-contacts -- --destination=<destination_id> --sources=<source_id1>,<source_id2> | ||
${bold('OPTIONS')} | ||
--destination=<destination_id> | ||
Specifies the ID of the contact that should receive the moving contacts and reports. | ||
--sources=<source_id1>,<source_id2> | ||
A comma delimited list of IDs of contacts which will be deleted. The hierarchy of contacts and reports under it will be moved to be under the destination contact. | ||
--docDirectoryPath=<path to stage docs> | ||
Specifies the folder used to store the documents representing the changes in hierarchy. | ||
`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.