Skip to content

Commit

Permalink
Merge pull request #7145 from RocketChat/unsubscribe2js
Browse files Browse the repository at this point in the history
Convert file unsubscribe.coffee to js
  • Loading branch information
rodrigok authored Jun 1, 2017
2 parents ea8ce48 + 1ca33b3 commit 2bf97fe
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
4 changes: 1 addition & 3 deletions private/node_scripts/unsubscribe_csv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"version": "0.0.1",
"private": true,
"scripts": {
"start": "coffee unsubscribe.coffee",
"test": "mocha --compilers coffee:coffee-script --timeout 5s -R spec"
"start": "node unsubscribe.js"
},
"dependencies": {
"coffee-script": "~1.6.3",
"commander": "^2.9.0",
"ddp": "^0.11.0",
"line-by-line": "^0.1.3",
Expand Down
33 changes: 0 additions & 33 deletions private/node_scripts/unsubscribe_csv/unsubscribe.coffee

This file was deleted.

44 changes: 44 additions & 0 deletions private/node_scripts/unsubscribe_csv/unsubscribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import lineReader from 'line-reader';
import program from 'commander';
import wait from 'wait.for';
import {MongoClient} from 'mongodb';

program.usage('[options]').option('-v, --verbose', 'Verbose', (function(v, total) {
return total + 1;
}), 0).option('-M, --mongo-db [mongo db]', 'Mongo DB', 'localhost:27017').option('-N, --db-name [db name]', 'DB Name', 'meteor').on('--help', function() {
console.log(' Example:');
console.log('');
console.log(' $ coffee unsubscribe.coffee');
return console.log('');
}).parse(process.argv);

wait.launchFiber(function() {
const db = wait.forMethod(MongoClient, 'connect', `mongodb://${ program.mongoDb }/${ program.dbName }`, {
replSet: {
socketOptions: {
connectTimeoutMS: 300000
}
}
});

const User = db.collection('users');
return lineReader.eachLine('./unsubscribe.csv', function(line, last) {
const row = line.split(',');
if (program.verbose) {
console.log(row[0]);
}
return wait.launchFiber(function() {
wait.forMethod(User, 'update', {
'emails.address': row[0]
}, {
$set: {
'mailer.unsubscribed': true
}
});

if (last) {
return process.exit();
}
});
});
});

0 comments on commit 2bf97fe

Please sign in to comment.