From 1073e95cbbfd119c636ec0b739f7da10b787e55e Mon Sep 17 00:00:00 2001 From: Simon Nedjari Date: Fri, 26 Apr 2024 12:22:57 +0200 Subject: [PATCH] add videosCount query on classes-exchanegs endpoint --- server/controllers/statistics.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/controllers/statistics.ts b/server/controllers/statistics.ts index d966588b0..3b2f80ee7 100644 --- a/server/controllers/statistics.ts +++ b/server/controllers/statistics.ts @@ -1,3 +1,5 @@ +import { Raw } from 'typeorm'; + import { Activity } from '../entities/activity'; import { Comment } from '../entities/comment'; import { Student } from '../entities/student'; @@ -27,10 +29,17 @@ statisticsController.get({ path: '/contributions' }, async (_req, res) => { statisticsController.get({ path: '/classes-exchanges' }, async (_req, res) => { const activitiesCount = await activityRepository.count({ where: { user: { type: UserType.TEACHER } } }); const commentsCount = await commentRepository.count({ where: { user: { type: UserType.TEACHER } } }); + const videosCount = await AppDataSource.createQueryRunner().manager.query( + `SELECT COUNT(*) AS total_videos FROM activity, + JSON_TABLE(activity.content, "$[*]" COLUMNS (type VARCHAR(255) PATH "$.type")) AS content_types + WHERE content_types.type = 'video';`, + ); + res.sendJSON({ totalActivities: activitiesCount, + totalVideos: parseInt(videosCount[0].total_videos), totalComments: commentsCount, - }) + }); }); statisticsController.get({ path: '/student-accounts' }, async (_req, res) => {