Skip to content

Commit

Permalink
Add action: delete-forms
Browse files Browse the repository at this point in the history
Closes #53
  • Loading branch information
alxndrsn committed Jan 19, 2018
1 parent 9c43b62 commit f6f2cb0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ To achieve this, create a file called `settings.inherit.json` in your project's

* fetch from google docs/google sheets/google drive and save locally as `.xlsx`
* backup from server
* delete from server
* delete all forms from server
* delete specific form from server
* upload to server

## Resources
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-conf",
"version": "1.9.4",
"version": "1.10.0",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/cli/supported-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = [
'convert-collect-forms',
'convert-contact-forms',
'csv-to-docs',
'delete-forms',
'delete-all-forms',
'fetch-forms-from-google-drive',
'initialise-project-layout',
Expand Down
20 changes: 20 additions & 0 deletions src/fn/delete-forms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const info = require('../lib/log').info;
const pouch = require('../lib/db');
const warn = require('../lib/log').warn;

module.exports = (projectDir, couchUrl, extras) => {
const db = pouch(couchUrl);

if(!extras || !extras.length) {
warn('No forms specified for deleting.');
return;
}

return Promise.all(extras.map(formName => {
const docId = `form:${formName}`;
db.get(docId)
.then(doc => db.remove(doc))
.then(() => info('Deleted form:', formName))
.catch(e => warn(`Failed to remove form with doc ID ${docId}`, e));
}));
};

0 comments on commit f6f2cb0

Please sign in to comment.