зеркало из https://github.com/mozilla/CSOL-site.git
Refactor favoriting a badge to class method
This commit is contained in:
Родитель
27c6d1a4db
Коммит
7e9aa52eb9
|
@ -100,17 +100,14 @@ module.exports = function (app) {
|
|||
var data = req.remote;
|
||||
var badge = data.badge;
|
||||
var user = res.locals.user;
|
||||
var shortName = req.params.id; // assume if we got here id is valid input
|
||||
|
||||
favorite.findOrCreate({
|
||||
type: 'badge',
|
||||
itemId: req.params.id, // assume if we got here id is valid input
|
||||
LearnerId: user.id
|
||||
}).complete(function(err, fav) {
|
||||
favorite.favoriteBadge(user, shortName, function(err, fav) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.render('user/badge-favorited.html', {
|
||||
badge: badge
|
||||
badge: badge
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,5 +26,17 @@ module.exports = {
|
|||
model: 'Learner',
|
||||
type: 'belongsTo'
|
||||
}
|
||||
]
|
||||
],
|
||||
classMethods: {
|
||||
// favoriteBadge adds a badge to the list of a user's favorites
|
||||
favoriteBadge: function (user, shortName, callback) {
|
||||
this.create({type: 'badge', itemId: shortName, LearnerId: user.id}).
|
||||
success(function(fav) {
|
||||
callback(null, fav);
|
||||
}).
|
||||
error(function(err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче