Post --> Note

Closes #1411
This commit is contained in:
syuilo
2018-04-08 02:30:37 +09:00
parent c7106d250c
commit a1b490afa7
167 changed files with 4440 additions and 1762 deletions

View File

@ -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
});
}