Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
52 changes: 49 additions & 3 deletions controllers/serverController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ function checkIfInQueue(user, queue) {
return (false);
}

function findServerByName(serverName, servers){

for (var i = 0; i < servers.length; i++) {
if (servers[i].name.toLowerCase() == serverName.toLowerCase()) {
return (servers[i]);
}
}

return (null);
}

module.exports = {

all: function (req, res) {
Expand Down Expand Up @@ -286,15 +297,46 @@ module.exports = {
},

rest: {
all: function (req, res) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference between this and the regular all (which is also a regular json route) is that there is no check if a user is logged in, do you need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there is no "isFree" check.


try {

var query = ServerEnv.find({name: req.query.environment}).sort('order');

query.exec(function(err, serverEnvs) {

if (!err) {

res.json(serverEnvs[0]);

} else {

res.send(500);

}
});

} catch (err) { res.send(500); }
},

take: function (req, res) {
try {
module.exports.take(req.body, function(env) { res.json(env); });
module.exports.take(req.body, function(env) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this into a method and call it with res as a param in all places


// Extract and return just the requested server!
var srv = findServerByName(req.body.name, env.servers)
res.json(srv);
});
} catch (err) { res.send(500); }
},

extend: function (req, res) {
try {
module.exports.extend(req.body, function(env) { res.json(env); });
module.exports.extend(req.body, function(env) {
// Extract and return just the requested server!
var srv = findServerByName(req.body.name, env.servers)
res.json(srv);
});
} catch (err) { res.send(500); }
},

Expand All @@ -306,7 +348,11 @@ module.exports = {

queue: function(req, res) {
try {
module.exports.queue(req.body, function(env) { res.json(env); });
module.exports.queue(req.body, function(env) {
// Extract and return just the requested server!
var srv = findServerByName(req.body.name, env.servers)
res.json(srv);
});
} catch (err) { res.send(500); }
},

Expand Down
Loading