Merge branch 'news' of https://github.com/FreeCodeCamp/freecodecamp into news
This commit is contained in:
5
app.js
5
app.js
@ -289,6 +289,11 @@ app.get(
|
|||||||
storyController.json
|
storyController.json
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.post(
|
||||||
|
'/stories/comment/submit',
|
||||||
|
storyController.commentSubmit
|
||||||
|
);
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
'/stories/comments/:id',
|
'/stories/comments/:id',
|
||||||
storyController.comments
|
storyController.comments
|
||||||
|
@ -100,16 +100,6 @@ exports.comments = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
author: {},
|
|
||||||
comments: {
|
|
||||||
type: Array,
|
|
||||||
default: []
|
|
||||||
},
|
|
||||||
image:
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.storySubmission = function(req, res, next) {
|
exports.storySubmission = function(req, res, next) {
|
||||||
var data = req.body.data;
|
var data = req.body.data;
|
||||||
var storyLink = data.headline
|
var storyLink = data.headline
|
||||||
@ -147,3 +137,37 @@ exports.storySubmission = function(req, res, next) {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.commentSubmit = function(req, res, next) {
|
||||||
|
var data = req.body.data;
|
||||||
|
var comment = new Comment({
|
||||||
|
associatedPost: data.associatedPost,
|
||||||
|
body: data.body,
|
||||||
|
rank: 0,
|
||||||
|
upvotes: 0,
|
||||||
|
author: data.author,
|
||||||
|
comments: []
|
||||||
|
});
|
||||||
|
|
||||||
|
comment.save(function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500);
|
||||||
|
}
|
||||||
|
debug('this is data from save', data);
|
||||||
|
Story.find({'_id': comment.associatedPost}, function(err, associatedStory) {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500);
|
||||||
|
}
|
||||||
|
associatedStory = associatedStory.pop();
|
||||||
|
if (associatedStory) {
|
||||||
|
associatedStory.comments.push(data._id);
|
||||||
|
associatedStory.save(function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
res.status(500);
|
||||||
|
}
|
||||||
|
res.send(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -183,6 +183,33 @@ $(document).ready(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$('#story-submit').on('click', storySubmitButtonHandler);
|
$('#story-submit').on('click', storySubmitButtonHandler);
|
||||||
|
|
||||||
|
var commentSubmitButtonHandler = function commentSubmitButtonHandler() {
|
||||||
|
var data = $('#comment-box').val();
|
||||||
|
|
||||||
|
$('#comment-button').unbind('click');
|
||||||
|
$.post('/stories/comment/submit',
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
associatedPost: storyId,
|
||||||
|
body: data,
|
||||||
|
author: {
|
||||||
|
picture: user.profile.picture,
|
||||||
|
userId: user._id,
|
||||||
|
username: user.profile.username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function (xhr, textStatus, errorThrown) {
|
||||||
|
$('#comment-button').bind('click', commentSubmitButtonHandler);
|
||||||
|
})
|
||||||
|
.done(function (data, textStatus, xhr) {
|
||||||
|
//window.location = '/stories/' + JSON.parse(data).storyLink;
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
$('#comment-button').on('click', commentSubmitButtonHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);
|
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);
|
||||||
|
Reference in New Issue
Block a user