This commit is contained in:
Aya Morisawa 2017-02-27 16:50:36 +09:00
parent fed386f087
commit eecfe23e3a
5 changed files with 261 additions and 266 deletions

View File

@ -15,8 +15,7 @@ import Post from '../../models/post';
* @return {Promise<object>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
new Promise(async (res, rej) => {
// Get 'post_id' parameter
let postId = params.post_id;
if (postId === undefined || postId === null) {
@ -32,7 +31,7 @@ module.exports = (params, user) =>
return rej('post not found');
}
// Check arleady favorited
// Check already favorited
const exist = await Favorite.findOne({
post_id: post._id,
user_id: user._id
@ -51,4 +50,4 @@ module.exports = (params, user) =>
// Send response
res();
});
});

View File

@ -15,8 +15,7 @@ import Post from '../../models/post';
* @return {Promise<object>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
new Promise(async (res, rej) => {
// Get 'post_id' parameter
let postId = params.post_id;
if (postId === undefined || postId === null) {
@ -49,4 +48,4 @@ module.exports = (params, user) =>
// Send response
res();
});
});

View File

@ -17,8 +17,7 @@ import notify from '../../../common/notify';
* @return {Promise<object>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
new Promise(async (res, rej) => {
// Get 'post_id' parameter
let postId = params.post_id;
if (postId === undefined || postId === null) {
@ -90,4 +89,4 @@ module.exports = (params, user) =>
notify(post.user_id, user._id, 'like', {
post_id: post._id
});
});
});

View File

@ -17,8 +17,7 @@ import User from '../../../models/user';
* @return {Promise<object>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
new Promise(async (res, rej) => {
// Get 'post_id' parameter
let postId = params.post_id;
if (postId === undefined || postId === null) {
@ -82,4 +81,4 @@ module.exports = (params, user) =>
liked_count: -1
}
});
});
});

View File

@ -16,8 +16,7 @@ import notify from '../../../common/notify';
* @return {Promise<object>}
*/
module.exports = (params, user) =>
new Promise(async (res, rej) =>
{
new Promise(async (res, rej) => {
// Get 'post_id' parameter
const postId = params.post_id;
if (postId === undefined || postId === null) {
@ -75,7 +74,7 @@ module.exports = (params, user) =>
res();
const inc = {};
inc[`poll.choices.${ findWithAttr(post.poll.choices, 'id', choice) }.votes`] = 1;
inc[`poll.choices.${findWithAttr(post.poll.choices, 'id', choice)}.votes`] = 1;
console.log(inc);
@ -89,11 +88,11 @@ module.exports = (params, user) =>
post_id: post._id,
choice: choice
});
});
});
function findWithAttr(array, attr, value) {
for (let i = 0; i < array.length; i += 1) {
if(array[i][attr] === value) {
if (array[i][attr] === value) {
return i;
}
}