From bf09da1bc16de25f79379b7440de9b98be9ecb61 Mon Sep 17 00:00:00 2001 From: Simon Nedjari Date: Thu, 25 Apr 2024 14:40:07 +0200 Subject: [PATCH] add totalComments endpoint and api call --- server/controllers/statistics.ts | 11 +++++++++-- src/api/statistics/statistics.get.ts | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/controllers/statistics.ts b/server/controllers/statistics.ts index d9f9eb78c..d966588b0 100644 --- a/server/controllers/statistics.ts +++ b/server/controllers/statistics.ts @@ -1,4 +1,5 @@ import { Activity } from '../entities/activity'; +import { Comment } from '../entities/comment'; import { Student } from '../entities/student'; import { UserType } from '../entities/user'; import { AppDataSource } from '../utils/data-source'; @@ -7,6 +8,7 @@ import { Controller } from './controller'; export const statisticsController = new Controller('/statistics'); const activityRepository = AppDataSource.getRepository(Activity); +const commentRepository = AppDataSource.getRepository(Comment); const studentRepository = AppDataSource.getRepository(Student); statisticsController.get({ path: '/contributions' }, async (_req, res) => { @@ -22,8 +24,13 @@ statisticsController.get({ path: '/contributions' }, async (_req, res) => { ); }); -statisticsController.get({ path: '/publications' }, async (_req, res) => { - res.sendJSON(await activityRepository.count({ where: { user: { type: UserType.TEACHER } } })); +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 } } }); + res.sendJSON({ + totalActivities: activitiesCount, + totalComments: commentsCount, + }) }); statisticsController.get({ path: '/student-accounts' }, async (_req, res) => { diff --git a/src/api/statistics/statistics.get.ts b/src/api/statistics/statistics.get.ts index ccd373a13..a4c8c0282 100644 --- a/src/api/statistics/statistics.get.ts +++ b/src/api/statistics/statistics.get.ts @@ -17,18 +17,18 @@ export const useGetContributions = () => { return useQuery(['activities'], () => getContributions()); }; -async function getPublications(): Promise { +async function getClassesExchanges(): Promise { return ( await axiosRequest({ method: 'GET', baseURL: '/api', - url: '/statistics/publications', + url: '/statistics/classes-exchanges', }) ).data; } -export const useGetPublications = () => { - return useQuery(['activities'], () => getPublications()); +export const useGetClassesExchanges = () => { + return useQuery(['activities', 'comments'], () => getClassesExchanges()); }; async function getStudentAccounts(): Promise {