From 25b3c2764798bf0b81180c03d27d3cf417e7589a Mon Sep 17 00:00:00 2001 From: Simon Nedjari Date: Tue, 23 Apr 2024 14:44:18 +0200 Subject: [PATCH] add count classroom publications request --- server/controllers/statistics.ts | 4 ++++ src/api/statistics/statistics.get.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/controllers/statistics.ts b/server/controllers/statistics.ts index 4f6475847..d9f9eb78c 100644 --- a/server/controllers/statistics.ts +++ b/server/controllers/statistics.ts @@ -22,6 +22,10 @@ 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: '/student-accounts' }, async (_req, res) => { res.sendJSON( await studentRepository diff --git a/src/api/statistics/statistics.get.ts b/src/api/statistics/statistics.get.ts index 696733af9..ccd373a13 100644 --- a/src/api/statistics/statistics.get.ts +++ b/src/api/statistics/statistics.get.ts @@ -1,7 +1,7 @@ import { useQuery } from 'react-query'; -import type { ContributionStats, StudentAccountsStats } from 'types/statistics.type'; import { axiosRequest } from 'src/utils/axiosRequest'; +import type { ContributionStats, StudentAccountsStats } from 'types/statistics.type'; async function getContributions(): Promise { return ( @@ -17,6 +17,20 @@ export const useGetContributions = () => { return useQuery(['activities'], () => getContributions()); }; +async function getPublications(): Promise { + return ( + await axiosRequest({ + method: 'GET', + baseURL: '/api', + url: '/statistics/publications', + }) + ).data; +} + +export const useGetPublications = () => { + return useQuery(['activities'], () => getPublications()); +}; + async function getStudentAccounts(): Promise { return ( await axiosRequest({