Skip to content

Commit

Permalink
Merge pull request #911 from parlemonde/ft/VIL-375
Browse files Browse the repository at this point in the history
add videosCount query on classes-exchanges endpoint
  • Loading branch information
SimNed authored Apr 26, 2024
2 parents 10d3bc0 + 1073e95 commit ce23912
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/controllers/statistics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Raw } from 'typeorm';

Check warning on line 1 in server/controllers/statistics.ts

View workflow job for this annotation

GitHub Actions / lint

'Raw' is defined but never used

import { Activity } from '../entities/activity';
import { Comment } from '../entities/comment';
import { Student } from '../entities/student';
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit ce23912

Please sign in to comment.