Skip to content

Commit

Permalink
add totalComments endpoint and api call
Browse files Browse the repository at this point in the history
  • Loading branch information
SimNed committed Apr 25, 2024
1 parent e26f22c commit bf09da1
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 bf09da1

Please sign in to comment.