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) => {