Skip to content

Commit

Permalink
#81 Expose new recent activity feature via graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery committed Nov 26, 2023
1 parent 363c148 commit e8fe300
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/activity/activity.gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { QuizlordContext } from '..';
import { authorisationService, activityService } from '../service.locator';

async function activityFeed(_: unknown, _params: Record<string, never>, context: QuizlordContext) {
authorisationService.requireUserRole(context, 'USER');

return activityService.getRecentActivity();
}

export const activityQueries = {
activityFeed,
};
16 changes: 16 additions & 0 deletions src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ const typeDefs = gql`
averageScorePercentage: Float!
}
type RecentActivityAction {
name: String!
link: String!
}
type RecentActivityItem {
date: Date!
text: String!
action: RecentActivityAction
}
"Available filters for the quizzes query"
input QuizFilters {
"""
Expand Down Expand Up @@ -166,6 +177,11 @@ const typeDefs = gql`
"The sorting option to use"
sortedBy: IndividualUserStatisticsSortOption
): [IndividualUserStatistic]
"""
Get the most recent activities.
"""
activityFeed: [RecentActivityItem]
}
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 @@ -12,6 +12,7 @@ import { authenticationService, prismaService, queueService, userService } from
import config from './config/config';
import typeDefs from './gql';
import { userQueries } from './user/user.gql';
import { activityQueries } from './activity/activity.gql';
import { quizMutations, quizQueries } from './quiz/quiz.gql';
import { Role } from './user/user.dto';
import { statisticsQueries } from './statistics/statistics.gql';
Expand Down Expand Up @@ -41,6 +42,7 @@ const resolvers = {
...quizQueries,
...userQueries,
...statisticsQueries,
...activityQueries,
},
Mutation: {
...quizMutations,
Expand Down
4 changes: 4 additions & 0 deletions src/service.locator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ActivityService } from './activity/activity.service';
import { AuthenticationService } from './auth/authentication.service';
import { AuthorisationService } from './auth/authorisation.service';
import { PrismaService } from './database/prisma.service';
Expand Down Expand Up @@ -37,3 +38,6 @@ export const queueService = new SQSQueueService(quizService);

// statistics
export const statisticsService = new StatisticsService(userService, quizService, memoryCache);

// activity
export const activityService = new ActivityService(quizService);

0 comments on commit e8fe300

Please sign in to comment.