Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/ole-vi/planet-scripts#readme",
"dependencies": {
"btoa": "^1.2.1",
"request": "^2.88.0"
}
}
27 changes: 26 additions & 1 deletion update-logs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const request = require('request');
const btoa = require('btoa');

const user = process.argv[2];
const pass = process.argv[3];
Expand Down Expand Up @@ -28,11 +29,35 @@ const updateDocs = (docs, db, callback) => {
};

const addParentToConfiguration = (configurations) => {
updateDocs(configurations.map(config => config.parentCode = parentCode), () => {
updateDocs(configurations.map(config => ({ ...config, parentCode})), 'configurations', () => {
createConfigurationReplication(configurations[0]);
console.log('Configurations updated');
});
}

const createConfigurationReplication = (configuration) => {
const replicationAddress = protocol + '://' + user + ':' + pass + '@localhost:5984/';
const replicationObject = {
// Name the id always after the local database
'_id': 'configuration_push_' + Date.now(),
'source': {
'url': replicationAddress + 'configurations'
},
'target': {
'headers': {
'Authorization': 'Basic ' + btoa(configuration.adminName + ':' + pass)
},
'url': 'https://' + configuration.parentDomain + '/communityregistrationrequests'
},
'create_target': false,
'owner': user,
'continuous': false
};
request.post({ uri: couchAddress + '_replicator', body: replicationObject, json: true }, () => {
console.log('Configuration replicating to parent');
});
}

const appendPlanetCodes = (array, codeField) => {
return array.map(item => ({ ...item, parentCode, [codeField]: code }));
};
Expand Down