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

View file

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

View file

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

View file

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

View file

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

View file

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