From 160185b108fd297959c58ca3e397d9830509094c Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 18 Aug 2018 05:43:09 +0900 Subject: [PATCH] Fix bug --- src/server/api/endpoints/aggregation/notes.ts | 15 ++++++++++----- src/server/api/endpoints/aggregation/users.ts | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/server/api/endpoints/aggregation/notes.ts b/src/server/api/endpoints/aggregation/notes.ts index b745c86631..59dd46ae2e 100644 --- a/src/server/api/endpoints/aggregation/notes.ts +++ b/src/server/api/endpoints/aggregation/notes.ts @@ -1,15 +1,20 @@ import $ from 'cafy'; import Note from '../../../../models/note'; +export const meta = { + requireCredential: true, + requireAdmin: true +}; + /** * Aggregate notes */ export default (params: any) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); - if (limitErr) return rej('invalid limit param'); - const query = [{ + createdAt: { + $gt: new Date(new Date().setFullYear(new Date().getFullYear() - 1)) + } + }, { $project: { renoteId: '$renoteId', replyId: '$replyId', @@ -84,7 +89,7 @@ export default (params: any) => new Promise(async (res, rej) => { const graph = []; - for (let i = 0; i < limit; i++) { + for (let i = 0; i < 365; i++) { const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter((d: any) => diff --git a/src/server/api/endpoints/aggregation/users.ts b/src/server/api/endpoints/aggregation/users.ts index 2e397545de..bb36fbfe46 100644 --- a/src/server/api/endpoints/aggregation/users.ts +++ b/src/server/api/endpoints/aggregation/users.ts @@ -1,15 +1,20 @@ import $ from 'cafy'; import User from '../../../../models/user'; +export const meta = { + requireCredential: true, + requireAdmin: true +}; + /** * Aggregate users */ export default (params: any) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); - if (limitErr) return rej('invalid limit param'); - const query = [{ + createdAt: { + $gt: new Date(new Date().setFullYear(new Date().getFullYear() - 1)) + } + }, { $project: { host: '$host', createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST @@ -64,7 +69,7 @@ export default (params: any) => new Promise(async (res, rej) => { const graph = []; - for (let i = 0; i < limit; i++) { + for (let i = 0; i < 365; i++) { const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter((d: any) =>