summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/polls
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/posts/polls')
-rw-r--r--src/api/endpoints/posts/polls/recommendation.ts8
-rw-r--r--src/api/endpoints/posts/polls/vote.ts32
2 files changed, 20 insertions, 20 deletions
diff --git a/src/api/endpoints/posts/polls/recommendation.ts b/src/api/endpoints/posts/polls/recommendation.ts
index 4a3fa3f55e..19ef0975fa 100644
--- a/src/api/endpoints/posts/polls/recommendation.ts
+++ b/src/api/endpoints/posts/polls/recommendation.ts
@@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Get votes
const votes = await Vote.find({
- user_id: user._id
+ userId: user._id
}, {
fields: {
_id: false,
- post_id: true
+ postId: true
}
});
- const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : [];
+ const nin = votes && votes.length != 0 ? votes.map(v => v.postId) : [];
const posts = await Post
.find({
_id: {
$nin: nin
},
- user_id: {
+ userId: {
$ne: user._id
},
poll: {
diff --git a/src/api/endpoints/posts/polls/vote.ts b/src/api/endpoints/posts/polls/vote.ts
index 16ce76a6fa..e87474ae6e 100644
--- a/src/api/endpoints/posts/polls/vote.ts
+++ b/src/api/endpoints/posts/polls/vote.ts
@@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event';
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
- // Get 'post_id' parameter
- const [postId, postIdErr] = $(params.post_id).id().$;
- if (postIdErr) return rej('invalid post_id param');
+ // Get 'postId' parameter
+ const [postId, postIdErr] = $(params.postId).id().$;
+ if (postIdErr) return rej('invalid postId param');
// Get votee
const post = await Post.findOne({
@@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// if already voted
const exist = await Vote.findOne({
- post_id: post._id,
- user_id: user._id
+ postId: post._id,
+ userId: user._id
});
if (exist !== null) {
@@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Create vote
await Vote.insert({
- created_at: new Date(),
- post_id: post._id,
- user_id: user._id,
+ createdAt: new Date(),
+ postId: post._id,
+ userId: user._id,
choice: choice
});
@@ -73,27 +73,27 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
publishPostStream(post._id, 'poll_voted');
// Notify
- notify(post.user_id, user._id, 'poll_vote', {
- post_id: post._id,
+ notify(post.userId, user._id, 'poll_vote', {
+ postId: post._id,
choice: choice
});
// Fetch watchers
Watching
.find({
- post_id: post._id,
- user_id: { $ne: user._id },
+ postId: post._id,
+ userId: { $ne: user._id },
// 削除されたドキュメントは除く
- deleted_at: { $exists: false }
+ deletedAt: { $exists: false }
}, {
fields: {
- user_id: true
+ userId: true
}
})
.then(watchers => {
watchers.forEach(watcher => {
- notify(watcher.user_id, user._id, 'poll_vote', {
- post_id: post._id,
+ notify(watcher.userId, user._id, 'poll_vote', {
+ postId: post._id,
choice: choice
});
});