From 901bcf5c188ea79350fecd499ad76460b866617b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Apr 2022 10:53:35 +0200 Subject: Add ability to set start/end date to timeserie --- server/controllers/api/videos/stats.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'server/controllers/api/videos/stats.ts') diff --git a/server/controllers/api/videos/stats.ts b/server/controllers/api/videos/stats.ts index 5f8513e9e..71452d9f0 100644 --- a/server/controllers/api/videos/stats.ts +++ b/server/controllers/api/videos/stats.ts @@ -1,6 +1,6 @@ import express from 'express' import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' -import { VideoStatsTimeserieMetric } from '@shared/models' +import { VideoStatsTimeserieMetric, VideoStatsTimeserieQuery } from '@shared/models' import { asyncMiddleware, authenticate, @@ -57,10 +57,23 @@ async function getTimeserieStats (req: express.Request, res: express.Response) { const video = res.locals.videoAll const metric = req.params.metric as VideoStatsTimeserieMetric + const query = req.query as VideoStatsTimeserieQuery + const stats = await LocalVideoViewerModel.getTimeserieStats({ video, - metric + metric, + startDate: query.startDate ?? buildOneMonthAgo().toISOString(), + endDate: query.endDate ?? new Date().toISOString() }) return res.json(stats) } + +function buildOneMonthAgo () { + const monthAgo = new Date() + monthAgo.setHours(0, 0, 0, 0) + + monthAgo.setDate(monthAgo.getDate() - 29) + + return monthAgo +} -- cgit v1.2.3