From cebea4e94c15b5a75da40801683b2c290a7e6fdb Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 8 Apr 2018 04:02:12 +0900 Subject: Some bug fixes and clean ups --- .../api/endpoints/aggregation/notes/reaction.ts | 76 ---------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/server/api/endpoints/aggregation/notes/reaction.ts (limited to 'src/server/api/endpoints/aggregation/notes/reaction.ts') diff --git a/src/server/api/endpoints/aggregation/notes/reaction.ts b/src/server/api/endpoints/aggregation/notes/reaction.ts deleted file mode 100644 index 586e8c2d85..0000000000 --- a/src/server/api/endpoints/aggregation/notes/reaction.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Note from '../../../../../models/note'; -import Reaction from '../../../../../models/note-reaction'; - -/** - * Aggregate reaction of a note - * - * @param {any} params - * @return {Promise} - */ -module.exports = (params) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $(params.noteId).id().$; - if (noteIdErr) return rej('invalid noteId param'); - - // Lookup note - const note = await Note.findOne({ - _id: noteId - }); - - if (note === null) { - return rej('note not found'); - } - - const datas = await Reaction - .aggregate([ - { $match: { noteId: note._id } }, - { $project: { - createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST - }}, - { $project: { - date: { - year: { $year: '$createdAt' }, - month: { $month: '$createdAt' }, - day: { $dayOfMonth: '$createdAt' } - } - }}, - { $group: { - _id: '$date', - count: { $sum: 1 } - }} - ]); - - datas.forEach(data => { - data.date = data._id; - delete data._id; - }); - - const graph = []; - - for (let i = 0; i < 30; i++) { - const day = new Date(new Date().setDate(new Date().getDate() - i)); - - const data = datas.filter(d => - d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() - )[0]; - - if (data) { - graph.push(data); - } else { - graph.push({ - date: { - year: day.getFullYear(), - month: day.getMonth() + 1, // In JavaScript, month is zero-based. - day: day.getDate() - }, - count: 0 - }); - } - } - - res(graph); -}); -- cgit v1.2.3-freya