diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-08-18 23:15:16 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-08-18 23:15:16 +0900 |
| commit | c3cd0451ad4ba4ef7c15bb1a3cf54a19d8c5d2ef (patch) | |
| tree | 06b1a11efb4c371085cc9ba963e5771f01c16439 /src/services | |
| parent | wip (diff) | |
| download | sharkey-c3cd0451ad4ba4ef7c15bb1a3cf54a19d8c5d2ef.tar.gz sharkey-c3cd0451ad4ba4ef7c15bb1a3cf54a19d8c5d2ef.tar.bz2 sharkey-c3cd0451ad4ba4ef7c15bb1a3cf54a19d8c5d2ef.zip | |
wip
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/update-chart.ts | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/services/update-chart.ts b/src/services/update-chart.ts index f6835fb789..f7997cb774 100644 --- a/src/services/update-chart.ts +++ b/src/services/update-chart.ts @@ -1,6 +1,6 @@ import { INote } from '../models/note'; import Chart, { IChart } from '../models/chart'; -import { isLocalUser } from '../models/user'; +import { isLocalUser, IUser } from '../models/user'; async function getTodayStats(): Promise<IChart> { const now = new Date(); @@ -22,7 +22,7 @@ async function getTodayStats(): Promise<IChart> { // 「昨日の」と決め打ちせずに「もっとも最近の」とします const mostRecentStats = await Chart.findOne({}, { sort: { - createdAt: -1 + date: -1 } }); @@ -114,6 +114,22 @@ async function update(inc: any) { }); } +export async function updateUserStats(user: IUser, isAdditional: boolean) { + const inc = {} as any; + + const val = isAdditional ? 1 : -1; + + if (isLocalUser(user)) { + inc['users.local.total'] = val; + inc['users.local.diff'] = val; + } else { + inc['users.remote.total'] = val; + inc['users.remote.diff'] = val; + } + + await update(inc); +} + export async function updateNoteStats(note: INote, isAdditional: boolean) { const inc = {} as any; |