@ -2,32 +2,32 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Post from '../../../../../models/post';
|
||||
import Reaction from '../../../../../models/post-reaction';
|
||||
import Note from '../../../../../models/note';
|
||||
import Reaction from '../../../../../models/note-reaction';
|
||||
|
||||
/**
|
||||
* Aggregate reaction of a post
|
||||
* Aggregate reaction of a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
_id: postId
|
||||
// Lookup note
|
||||
const note = await Note.findOne({
|
||||
_id: noteId
|
||||
});
|
||||
|
||||
if (post === null) {
|
||||
return rej('post not found');
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
const datas = await Reaction
|
||||
.aggregate([
|
||||
{ $match: { postId: post._id } },
|
||||
{ $match: { noteId: note._id } },
|
||||
{ $project: {
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
@ -2,34 +2,34 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Post from '../../../../../models/post';
|
||||
import Reaction from '../../../../../models/post-reaction';
|
||||
import Note from '../../../../../models/note';
|
||||
import Reaction from '../../../../../models/note-reaction';
|
||||
|
||||
/**
|
||||
* Aggregate reactions of a post
|
||||
* Aggregate reactions of a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
_id: postId
|
||||
// Lookup note
|
||||
const note = await Note.findOne({
|
||||
_id: noteId
|
||||
});
|
||||
|
||||
if (post === null) {
|
||||
return rej('post not found');
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
const startTime = new Date(new Date().setMonth(new Date().getMonth() - 1));
|
||||
|
||||
const reactions = await Reaction
|
||||
.find({
|
||||
postId: post._id,
|
||||
noteId: note._id,
|
||||
$or: [
|
||||
{ deletedAt: { $exists: false } },
|
||||
{ deletedAt: { $gt: startTime } }
|
||||
@ -40,7 +40,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
},
|
||||
fields: {
|
||||
_id: false,
|
||||
postId: false
|
||||
noteId: false
|
||||
}
|
||||
});
|
||||
|
@ -2,31 +2,31 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Post from '../../../../../models/post';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Aggregate reply of a post
|
||||
* Aggregate reply of a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
_id: postId
|
||||
// Lookup note
|
||||
const note = await Note.findOne({
|
||||
_id: noteId
|
||||
});
|
||||
|
||||
if (post === null) {
|
||||
return rej('post not found');
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
const datas = await Post
|
||||
const datas = await Note
|
||||
.aggregate([
|
||||
{ $match: { reply: post._id } },
|
||||
{ $match: { reply: note._id } },
|
||||
{ $project: {
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
@ -2,31 +2,31 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Post from '../../../../../models/post';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Aggregate repost of a post
|
||||
* Aggregate renote of a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
_id: postId
|
||||
// Lookup note
|
||||
const note = await Note.findOne({
|
||||
_id: noteId
|
||||
});
|
||||
|
||||
if (post === null) {
|
||||
return rej('post not found');
|
||||
if (note === null) {
|
||||
return rej('note not found');
|
||||
}
|
||||
|
||||
const datas = await Post
|
||||
const datas = await Note
|
||||
.aggregate([
|
||||
{ $match: { repostId: post._id } },
|
||||
{ $match: { renoteId: note._id } },
|
||||
{ $project: {
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
@ -2,10 +2,10 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Post from '../../../../models/post';
|
||||
import Note from '../../../../models/note';
|
||||
|
||||
/**
|
||||
* Aggregate posts
|
||||
* Aggregate notes
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
@ -15,10 +15,10 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const datas = await Post
|
||||
const datas = await Note
|
||||
.aggregate([
|
||||
{ $project: {
|
||||
repostId: '$repostId',
|
||||
renoteId: '$renoteId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
@ -30,13 +30,13 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
if: { $ne: ['$renoteId', null] },
|
||||
then: 'renote',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
else: 'note'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,8 +59,8 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||
data.date = data._id;
|
||||
delete data._id;
|
||||
|
||||
data.posts = (data.data.filter(x => x.type == 'post')[0] || { count: 0 }).count;
|
||||
data.reposts = (data.data.filter(x => x.type == 'repost')[0] || { count: 0 }).count;
|
||||
data.notes = (data.data.filter(x => x.type == 'note')[0] || { count: 0 }).count;
|
||||
data.renotes = (data.data.filter(x => x.type == 'renote')[0] || { count: 0 }).count;
|
||||
data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count;
|
||||
|
||||
delete data.data;
|
||||
@ -79,8 +79,8 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||
graph.push(data);
|
||||
} else {
|
||||
graph.push({
|
||||
posts: 0,
|
||||
reposts: 0,
|
||||
notes: 0,
|
||||
renotes: 0,
|
||||
replies: 0
|
||||
});
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User from '../../../../../models/user';
|
||||
import Post from '../../../../../models/post';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
// TODO: likeやfollowも集計
|
||||
|
||||
@ -35,11 +35,11 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
return rej('user not found');
|
||||
}
|
||||
|
||||
const datas = await Post
|
||||
const datas = await Note
|
||||
.aggregate([
|
||||
{ $match: { userId: user._id } },
|
||||
{ $project: {
|
||||
repostId: '$repostId',
|
||||
renoteId: '$renoteId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
@ -51,13 +51,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
if: { $ne: ['$renoteId', null] },
|
||||
then: 'renote',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
else: 'note'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,8 +80,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
data.date = data._id;
|
||||
delete data._id;
|
||||
|
||||
data.posts = (data.data.filter(x => x.type == 'post')[0] || { count: 0 }).count;
|
||||
data.reposts = (data.data.filter(x => x.type == 'repost')[0] || { count: 0 }).count;
|
||||
data.notes = (data.data.filter(x => x.type == 'note')[0] || { count: 0 }).count;
|
||||
data.renotes = (data.data.filter(x => x.type == 'renote')[0] || { count: 0 }).count;
|
||||
data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count;
|
||||
|
||||
delete data.data;
|
||||
@ -105,8 +105,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
month: day.getMonth() + 1, // In JavaScript, month is zero-based.
|
||||
day: day.getDate()
|
||||
},
|
||||
posts: 0,
|
||||
reposts: 0,
|
||||
notes: 0,
|
||||
renotes: 0,
|
||||
replies: 0
|
||||
});
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User from '../../../../../models/user';
|
||||
import Post from '../../../../../models/post';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Aggregate post of a user
|
||||
* Aggregate note of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
@ -29,11 +29,11 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
return rej('user not found');
|
||||
}
|
||||
|
||||
const datas = await Post
|
||||
const datas = await Note
|
||||
.aggregate([
|
||||
{ $match: { userId: user._id } },
|
||||
{ $project: {
|
||||
repostId: '$repostId',
|
||||
renoteId: '$renoteId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
@ -45,13 +45,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
if: { $ne: ['$renoteId', null] },
|
||||
then: 'renote',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
else: 'note'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,8 +74,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
data.date = data._id;
|
||||
delete data._id;
|
||||
|
||||
data.posts = (data.data.filter(x => x.type == 'post')[0] || { count: 0 }).count;
|
||||
data.reposts = (data.data.filter(x => x.type == 'repost')[0] || { count: 0 }).count;
|
||||
data.notes = (data.data.filter(x => x.type == 'note')[0] || { count: 0 }).count;
|
||||
data.renotes = (data.data.filter(x => x.type == 'renote')[0] || { count: 0 }).count;
|
||||
data.replies = (data.data.filter(x => x.type == 'reply')[0] || { count: 0 }).count;
|
||||
|
||||
delete data.data;
|
||||
@ -99,8 +99,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
month: day.getMonth() + 1, // In JavaScript, month is zero-based.
|
||||
day: day.getDate()
|
||||
},
|
||||
posts: 0,
|
||||
reposts: 0,
|
||||
notes: 0,
|
||||
renotes: 0,
|
||||
replies: 0
|
||||
});
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User from '../../../../../models/user';
|
||||
import Reaction from '../../../../../models/post-reaction';
|
||||
import Reaction from '../../../../../models/note-reaction';
|
||||
|
||||
/**
|
||||
* Aggregate reaction of a user
|
||||
|
Reference in New Issue
Block a user