Skip to content

Commit

Permalink
Merge pull request #909 from parlemonde/ft/VIL-370
Browse files Browse the repository at this point in the history
add totalComments endpoint and api call
  • Loading branch information
SimNed authored Apr 25, 2024
2 parents e26f22c + bf09da1 commit 10d3bc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions server/controllers/statistics.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand All @@ -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,
})

Check failure on line 33 in server/controllers/statistics.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
});

statisticsController.get({ path: '/student-accounts' }, async (_req, res) => {
Expand Down
8 changes: 4 additions & 4 deletions src/api/statistics/statistics.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ export const useGetContributions = () => {
return useQuery(['activities'], () => getContributions());
};

async function getPublications(): Promise<number> {
async function getClassesExchanges(): Promise<number> {
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<StudentAccountsStats> {
Expand Down

0 comments on commit 10d3bc0

Please sign in to comment.