Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Changed all the indents to the spaces(tab size 4)
Browse files Browse the repository at this point in the history
  • Loading branch information
samof76 committed May 14, 2014
1 parent 9503720 commit 7cf1fc2
Show file tree
Hide file tree
Showing 49 changed files with 1,917 additions and 1,667 deletions.
146 changes: 73 additions & 73 deletions app/controllers/articles.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,129 +4,129 @@
* Module dependencies.
*/
var mongoose = require('mongoose'),
Article = mongoose.model('Article'),
_ = require('lodash');
Article = mongoose.model('Article'),
_ = require('lodash');

/**
* Get the error message from error object
*/
var getErrorMessage = function(err) {
var message = '';
var message = '';

if (err.code) {
switch (err.code) {
case 11000:
case 11001:
message = 'Article already exists';
break;
default:
message = 'Something went wrong';
}
} else {
for (var errName in err.errors) {
if (err.errors[errName].message) message = err.errors[errName].message;
}
}
if (err.code) {
switch (err.code) {
case 11000:
case 11001:
message = 'Article already exists';
break;
default:
message = 'Something went wrong';
}
} else {
for (var errName in err.errors) {
if (err.errors[errName].message) message = err.errors[errName].message;
}
}

return message;
return message;
};

/**
* Create a article
*/
exports.create = function(req, res) {
var article = new Article(req.body);
article.user = req.user;
var article = new Article(req.body);
article.user = req.user;

article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
};

/**
* Show the current article
*/
exports.read = function(req, res) {
res.jsonp(req.article);
res.jsonp(req.article);
};

/**
* Update a article
*/
exports.update = function(req, res) {
var article = req.article;
var article = req.article;

article = _.extend(article, req.body);
article = _.extend(article, req.body);

article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
article.save(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
};

/**
* Delete an article
*/
exports.delete = function(req, res) {
var article = req.article;
var article = req.article;

article.remove(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
article.remove(function(err) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(article);
}
});
};

/**
* List of Articles
*/
exports.list = function(req, res) {
Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(articles);
}
});
Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
if (err) {
return res.send(400, {
message: getErrorMessage(err)
});
} else {
res.jsonp(articles);
}
});
};

/**
* Article middleware
*/
exports.articleByID = function(req, res, next, id) {
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();
});
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();
});
};

/**
* Article authorization middleware
*/
exports.hasAuthorization = function(req, res, next) {
if (req.article.user.id !== req.user.id) {
return res.send(403, {
message: 'User is not authorized'
});
}
next();
};
if (req.article.user.id !== req.user.id) {
return res.send(403, {
message: 'User is not authorized'
});
}
next();
};
8 changes: 4 additions & 4 deletions app/controllers/core.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Module dependencies.
*/
exports.index = function(req, res) {
res.render('index', {
user: req.user || null
});
};
res.render('index', {
user: req.user || null
});
};
Loading

0 comments on commit 7cf1fc2

Please sign in to comment.