Skip to content

Commit

Permalink
no bot_ for anyone
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Dec 31, 2013
1 parent 28046f2 commit cedfe1c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
25 changes: 13 additions & 12 deletions resources/bot/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ exports.validate = validate;
/// validate

function validate(req, res, next) {
console.log(req.params)
var err = joi.validate(req.params, schema);
if (err) res.send(new restify.InvalidArgumentError(err.message));
else next();
}

var schema = {
bot_id: joi.string().required(),
bot_name: joi.string().required(),
id: joi.string().required(),
name: joi.string().required(),
commands: joi.array().includes(joi.string()),
address: joi.string(),
description: joi.string(),
photourl: joi.string(),
livefeedurl: joi.string(),
bot_visible: joi.boolean()
photoURL: joi.string(),
liveFeedURL: joi.string(),
visible: joi.boolean()
};

/// create bot
Expand All @@ -38,16 +39,16 @@ function create(req, res, next) {
], done);

function createBot(cb) {
bot.bot_id = req.params.bot_id;
bot.bot_name = req.params.bot_name;
bot.bot_key = uuid();
bot.bot_state = false;
bot.bot_visible = req.params.bot_visible || true;
bot.id = req.params.id;
bot.name = req.params.name;
bot.key = uuid();
bot.state = false;
bot.visible = req.params.visible || true;
if (req.params.address) bot.address = req.params.address;
if (req.params.commands) bot.commands = req.params.commands;
if (req.params.description) bot.description = req.params.description;
if (req.params.photourl) bot.photourl = req.params.photourl;
if (req.params.livefeedurl) bot.livefeedurl = req.params.livefeedurl;
if (req.params.photoURL) bot.photoURL = req.params.photoURL;
if (req.params.liveFeedURL) bot.liveFeedURL = req.params.liveFeedURL;

cb();
}
Expand Down
26 changes: 13 additions & 13 deletions resources/bot/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ function validate(req, res, next) {
}

var schema = {
current_bot_id: joi.string().required(),
bot_id: joi.string(),
bot_name: joi.string(),
current_id: joi.string().required(),
id: joi.string(),
name: joi.string(),
commands: joi.array().includes(joi.string()),
address: joi.string(),
description: joi.string(),
photourl: joi.string(),
livefeedurl: joi.string(),
bot_visible: joi.boolean()
photoURL: joi.string(),
liveFeedURL: joi.string(),
visible: joi.boolean()
};

/// create bot

function edit(req, res, next) {
var currentBotId = req.params.current_bot_id;
var currentBotId = req.params.current_id;
assert(currentBotId, 'must have the current bot ID');

var bot;
Expand All @@ -53,14 +53,14 @@ function edit(req, res, next) {

function editBot(cb) {

if (req.params.bot_id) bot.bot_id = req.params.bot_id;
if (req.params.bot_name) bot.bot_name = req.params.bot_name;
if (req.params.bot_key) bot.bot_key = req.params.bot_key;
if (req.params.bot_state !== null) bot.bot_state = req.params.bot_state;
if (req.params.id) bot.id = req.params.id;
if (req.params.name) bot.name = req.params.name;
if (req.params.key) bot.key = req.params.key;
if (req.params.state !== null) bot.state = req.params.state;
if (req.params.address) bot.address = req.params.address;
if (req.params.commands) bot.commands = req.params.commands;
if (req.params.livefeedurl) bot.livefeedurl = req.params.livefeedurl;
if (req.params.photourl) bot.photourl = req.params.photourl;
if (req.params.liveFeedURL) bot.liveFeedURL = req.params.liveFeedURL;
if (req.params.photoURL) bot.photoURL = req.params.photoURL;
if (req.params.description) bot.description = req.params.description;
cb();
}
Expand Down
16 changes: 8 additions & 8 deletions resources/bot/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ function validate(req, res, next) {
}

var schema = {
bot_id: joi.string().required(),
id: joi.string().required(),
};

/// get bot

function get(req, res, next) {

var botId = req.params.bot_id;
var botId = req.params.id;
var bot = {};

async.series([
Expand All @@ -35,14 +35,14 @@ function get(req, res, next) {
function gotBot(err, result) {
if (err) cb(err);
if (result.length > 0) {
if (result[0].bot_id) bot.bot_id = result[0].bot_id;
if (result[0].bot_name) bot.bot_name = result[0].bot_name;
if (result[0].bot_key) bot.bot_key = result[0].bot_key;
if (result[0].bot_state) bot.bot_state = result[0].bot_state;
if (result[0].id) bot.id = result[0].id;
if (result[0].name) bot.name = result[0].name;
if (result[0].key) bot.key = result[0].key;
if (result[0].state) bot.state = result[0].state;
if (result[0].address) bot.address = result[0].address;
if (result[0].commands) bot.commands = result[0].commands;
if (result[0].livefeedurl) bot.livefeedurl = result[0].livefeedurl;
if (result[0].photourl) bot.photourl = result[0].photourl;
if (result[0].liveFeedURL) bot.liveFeedURL = result[0].liveFeedURL;
if (result[0].photoURL) bot.photoURL = result[0].photoURL;
if (result[0].description) bot.description = result[0].description;
cb();
} else {
Expand Down

0 comments on commit cedfe1c

Please sign in to comment.