Skip to content

Commit

Permalink
#66 Expose new statistics resolver to get individual user statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery committed Nov 4, 2023
1 parent e7bb25e commit 21fecd7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ const typeDefs = gql`
completion: QuizCompletion
}
type IndividualUserStatistic {
name: String
email: String!
totalQuizCompletions: Int!
averageScorePercentage: Float!
}
"Available filters for the quizzes query"
input QuizFilters {
"""
Expand Down Expand Up @@ -144,6 +151,7 @@ const typeDefs = gql`
"""
users(first: Int, after: String, sortedBy: UserSortOption): UserConnection
me: UserDetails
individualUserStatistics: [IndividualUserStatistic]
}
type Mutation {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import typeDefs from './gql';
import { userQueries } from './user/user.gql';
import { quizMutations, quizQueries } from './quiz/quiz.gql';
import { Role } from './user/user.dto';
import { statisticsQueries } from './statistics/statistics.gql';

const QUIZLORD_VERSION_HEADER = 'X-Quizlord-Api-Version';

Expand All @@ -39,6 +40,7 @@ const resolvers = {
Query: {
...quizQueries,
...userQueries,
...statisticsQueries,
},
Mutation: {
...quizMutations,
Expand Down
6 changes: 6 additions & 0 deletions src/statistics/statistics.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IndividualUserStatistic {
name?: string;
email: string;
totalQuizCompletions: number;
averageScorePercentage: number;
}
16 changes: 16 additions & 0 deletions src/statistics/statistics.gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { QuizlordContext } from '..';
import { authorisationService, statisticsService } from '../service.locator';
import { IndividualUserStatistic } from './statistics.dto';

async function individualUserStatistics(
_p: unknown,
_: void,
context: QuizlordContext,
): Promise<IndividualUserStatistic[]> {
authorisationService.requireUserRole(context, 'USER');
return statisticsService.getIndividualUserStatistics();
}

export const statisticsQueries = {
individualUserStatistics,
};

0 comments on commit 21fecd7

Please sign in to comment.