diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-21 14:15:02 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-21 14:15:02 +0900 |
| commit | 1bf8cbeb29af5f0d40487118749f64203ae1b901 (patch) | |
| tree | 7c8c08eb39742da989edf712b2ac8781266baf53 /src/server/api/endpoints/aggregation/users | |
| parent | Refactoring & Better stats aggregation (diff) | |
| download | sharkey-1bf8cbeb29af5f0d40487118749f64203ae1b901.tar.gz sharkey-1bf8cbeb29af5f0d40487118749f64203ae1b901.tar.bz2 sharkey-1bf8cbeb29af5f0d40487118749f64203ae1b901.zip | |
Clean up
Diffstat (limited to 'src/server/api/endpoints/aggregation/users')
| -rw-r--r-- | src/server/api/endpoints/aggregation/users/followers.ts | 61 | ||||
| -rw-r--r-- | src/server/api/endpoints/aggregation/users/following.ts | 61 |
2 files changed, 0 insertions, 122 deletions
diff --git a/src/server/api/endpoints/aggregation/users/followers.ts b/src/server/api/endpoints/aggregation/users/followers.ts deleted file mode 100644 index 94eb83febc..0000000000 --- a/src/server/api/endpoints/aggregation/users/followers.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../../misc/cafy-id'; -import User from '../../../../../models/user'; -import FollowedLog from '../../../../../models/followed-log'; - -/** - * Aggregate followers of a user - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).get(params.userId); - if (userIdErr) return rej('invalid userId param'); - - // Lookup user - const user = await User.findOne({ - _id: userId - }, { - fields: { - _id: true - } - }); - - if (user === null) { - return rej('user not found'); - } - - const today = new Date(); - const graph = []; - - today.setMinutes(0); - today.setSeconds(0); - today.setMilliseconds(0); - - let cursorDate = new Date(today.getTime()); - let cursorTime = cursorDate.setDate(new Date(today.getTime()).getDate() + 1); - - for (let i = 0; i < 30; i++) { - graph.push(FollowedLog.findOne({ - createdAt: { $lt: new Date(cursorTime / 1000) }, - userId: user._id - }, { - sort: { createdAt: -1 }, - }).then(log => { - cursorDate = new Date(today.getTime()); - cursorTime = cursorDate.setDate(today.getDate() - i); - - return { - date: { - year: cursorDate.getFullYear(), - month: cursorDate.getMonth() + 1, // In JavaScript, month is zero-based. - day: cursorDate.getDate() - }, - count: log ? log.count : 0 - }; - })); - } - - res(await Promise.all(graph)); -}); diff --git a/src/server/api/endpoints/aggregation/users/following.ts b/src/server/api/endpoints/aggregation/users/following.ts deleted file mode 100644 index d2e4d256fe..0000000000 --- a/src/server/api/endpoints/aggregation/users/following.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../../misc/cafy-id'; -import User from '../../../../../models/user'; -import FollowingLog from '../../../../../models/following-log'; - -/** - * Aggregate following of a user - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).get(params.userId); - if (userIdErr) return rej('invalid userId param'); - - // Lookup user - const user = await User.findOne({ - _id: userId - }, { - fields: { - _id: true - } - }); - - if (user === null) { - return rej('user not found'); - } - - const today = new Date(); - const graph = []; - - today.setMinutes(0); - today.setSeconds(0); - today.setMilliseconds(0); - - let cursorDate = new Date(today.getTime()); - let cursorTime = cursorDate.setDate(new Date(today.getTime()).getDate() + 1); - - for (let i = 0; i < 30; i++) { - graph.push(FollowingLog.findOne({ - createdAt: { $lt: new Date(cursorTime / 1000) }, - userId: user._id - }, { - sort: { createdAt: -1 }, - }).then(log => { - cursorDate = new Date(today.getTime()); - cursorTime = cursorDate.setDate(today.getDate() - i); - - return { - date: { - year: cursorDate.getFullYear(), - month: cursorDate.getMonth() + 1, // In JavaScript, month is zero-based. - day: cursorDate.getDate() - }, - count: log ? log.count : 0 - }; - })); - } - - res(await Promise.all(graph)); -}); |