real-votes-admin
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -35,3 +35,3 @@ #!/usr/bin/env node | ||
cli | ||
.command('addPoll', 'Creates a new poll') | ||
.command('createPoll', 'Creates a new poll') | ||
.action(function(args, callback) { | ||
@@ -85,3 +85,3 @@ this.prompt([ | ||
this.log(green('Successfully added poll!')); | ||
this.log(green('Successfully created poll!')); | ||
callback(); | ||
@@ -99,3 +99,3 @@ }); | ||
name: 'id', | ||
message: blue('Please enter the polls id you want to update: '), | ||
message: blue('Please enter the polls ID you want to update: '), | ||
}, | ||
@@ -140,47 +140,33 @@ { | ||
cli | ||
.command('deletePoll', 'deletes one poll') | ||
.action(function(args, callback) { | ||
this.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'id', | ||
message: blue('Please enter the polls ID you want to delete: '), | ||
}, | ||
], (answers) => { | ||
const input = inputVer(answers); | ||
if (input === true) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
.command('readAllPolls', 'Read all polls') | ||
.action(function(args, callback) { | ||
request.get(PollBaseUrl, (err, res, body) => { | ||
if (err) { | ||
this.log(err); | ||
return callback(); | ||
} | ||
const options = { | ||
url: PollBaseUrl + answers.id, | ||
auth: { | ||
username: 'admin', | ||
password: process.env.PASSWORD, | ||
}, | ||
}; | ||
if (res.statusCode !== 200) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
request.delete(options, (err, res) => { | ||
if (err) { | ||
this.log(err); | ||
return callback(); | ||
} | ||
if (res.statusCode !== 200) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
this.log(green('Successfully deleted poll!')); | ||
callback(); | ||
}); | ||
}); | ||
this.log(prettyjson.render(JSON.parse(body))); | ||
callback(); | ||
}); | ||
}); | ||
cli | ||
.command('viewAllPolls', 'Shows all polls') | ||
.command('readAllVotes', 'Shows all votes') | ||
.action(function(args, callback) { | ||
request.get(PollBaseUrl, (err, res, body) => { | ||
const options = { | ||
url: VoteBaseUrl, | ||
auth: { | ||
username: 'admin', | ||
password: process.env.PASSWORD, | ||
}, | ||
}; | ||
request.get(options, (err, res, body) => { | ||
if (err) { | ||
@@ -201,7 +187,20 @@ this.log(err); | ||
cli | ||
.command('viewAllVotes', 'Shows all votes') | ||
.action(function(args, callback) { | ||
.command('readOnePollVotes', 'Read votes for a single poll.') | ||
.action(function(args, callback) { | ||
this.prompt({ | ||
type: 'input', | ||
name: 'pollId', | ||
message: blue('Enter the ID of the poll you want to view votes for: '), | ||
}, | ||
(answers) => { | ||
const input = inputVer(answers); | ||
if (input === true) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
const options = { | ||
url: VoteBaseUrl, | ||
url: `${PollBaseUrl}${answers.pollId}/users`, | ||
auth: { | ||
@@ -212,2 +211,3 @@ username: 'admin', | ||
}; | ||
request.get(options, (err, res, body) => { | ||
@@ -228,14 +228,35 @@ if (err) { | ||
}); | ||
}); | ||
cli | ||
.command('deleteAllPolls', 'Deletes all polls') | ||
.action(function(args, callback) { | ||
this.prompt({ | ||
.command('destroyOnePoll', 'Destroys one poll') | ||
.action(function(args, callback) { | ||
this.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'confirmation', | ||
message: red('Are you sure you want to input all polls, \'y\' or \'n\': '), | ||
name: 'id', | ||
message: blue('Please enter the polls ID you want to delete: '), | ||
}, | ||
(answers) => { | ||
const input = inputVer(answers); | ||
if (input === true) { | ||
], (answers) => { | ||
const input = inputVer(answers); | ||
if (input === true) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
const options = { | ||
url: PollBaseUrl + answers.id, | ||
auth: { | ||
username: 'admin', | ||
password: process.env.PASSWORD, | ||
}, | ||
}; | ||
request.delete(options, (err, res) => { | ||
if (err) { | ||
this.log(err); | ||
return callback(); | ||
} | ||
if (res.statusCode !== 200) { | ||
this.log(red('Invalid input, exiting command...')); | ||
@@ -245,30 +266,10 @@ return callback(); | ||
if (answers.confirmation.toLowerCase() === 'n') return callback(); | ||
const options = { | ||
url: PollBaseUrl, | ||
auth: { | ||
username: 'admin', | ||
password: process.env.PASSWORD, | ||
}, | ||
}; | ||
request.delete(options, (err, res) => { | ||
if (err) { | ||
this.log(err); | ||
return callback(); | ||
} | ||
if (res.statusCode !== 200) { | ||
this.log(red('Invalid input, exiting command...')); | ||
return callback(); | ||
} | ||
this.log(green('Successfully deleted all polls.')); | ||
callback(); | ||
}); | ||
this.log(green('Successfully destroyed poll!')); | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
cli | ||
.command('deleteAllVotes', 'Deletes all votes') | ||
.command('destroyAllPolls', 'Deletes all polls') | ||
.action(function(args, callback) { | ||
@@ -278,3 +279,3 @@ this.prompt({ | ||
name: 'confirmation', | ||
message: red('Are you sure you want to delete all votes, \'y\' or \'n\': '), | ||
message: red('Are you sure you want to destroy all polls, \'y\' or \'n\': '), | ||
}, | ||
@@ -290,3 +291,3 @@ (answers) => { | ||
const options = { | ||
url: VoteBaseUrl, | ||
url: PollBaseUrl, | ||
auth: { | ||
@@ -309,3 +310,3 @@ username: 'admin', | ||
this.log(green('Successfully deleted all votes.')); | ||
this.log(green('Successfully destroyed all polls.')); | ||
callback(); | ||
@@ -317,8 +318,8 @@ }); | ||
cli | ||
.command('viewOnePollVotes', 'View votes for a single poll.') | ||
.command('destroyAllVotes', 'Destroy all votes') | ||
.action(function(args, callback) { | ||
this.prompt({ | ||
type: 'input', | ||
name: 'pollId', | ||
message: blue('Enter the ID of the Poll you want to view votes for: '), | ||
name: 'confirmation', | ||
message: red('Are you sure you want to destroy all votes, \'y\' or \'n\': '), | ||
}, | ||
@@ -332,4 +333,5 @@ (answers) => { | ||
if (answers.confirmation.toLowerCase() === 'n') return callback(); | ||
const options = { | ||
url: `${PollBaseUrl}${answers.pollId}/users`, | ||
url: VoteBaseUrl, | ||
auth: { | ||
@@ -341,3 +343,3 @@ username: 'admin', | ||
request.get(options, (err, res, body) => { | ||
request.delete(options, (err, res) => { | ||
if (err) { | ||
@@ -353,3 +355,3 @@ this.log(err); | ||
this.log(prettyjson.render(JSON.parse(body))); | ||
this.log(green('Successfully destroyed all votes.')); | ||
callback(); | ||
@@ -361,3 +363,3 @@ }); | ||
cli | ||
.command('deleteOnePollVotes', 'Delete votes for a single poll.') | ||
.command('destroyOnePollVotes', 'Destroy votes for a single poll.') | ||
.action(function(args, callback) { | ||
@@ -367,3 +369,3 @@ this.prompt({ | ||
name: 'pollId', | ||
message: blue('Enter the ID of the Poll you want to delete all votes for: '), | ||
message: blue('Enter the ID of the poll you want to destroy all votes for: '), | ||
}, | ||
@@ -427,3 +429,3 @@ (answers) => { | ||
cli | ||
.command('showResults', 'Show the results of the current poll') | ||
.command('readResults', 'Read the results of the current poll') | ||
.action(function(args, callback) { | ||
@@ -449,4 +451,4 @@ request.get(`${VoteBaseUrl}tally`, (err, res, body) => { | ||
.command( | ||
'showRealtimeResults', | ||
'Show the results of the current poll and keep them updated in real time' | ||
'readRealtimeResults', | ||
'Read the results of the current poll and keep them updated in real time' | ||
) | ||
@@ -453,0 +455,0 @@ .action(function(args, callback) { |
{ | ||
"name": "real-votes-admin", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Admin panel for the real-votes API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
19437