From e8fe300fe7f66019618639238ece99a63ad9268f Mon Sep 17 00:00:00 2001 From: Daniel Emery Date: Sun, 26 Nov 2023 14:49:47 +1030 Subject: [PATCH] #81 Expose new recent activity feature via graphql --- src/activity/activity.gql.ts | 12 ++++++++++++ src/gql.ts | 16 ++++++++++++++++ src/index.ts | 2 ++ src/service.locator.ts | 4 ++++ 4 files changed, 34 insertions(+) create mode 100644 src/activity/activity.gql.ts diff --git a/src/activity/activity.gql.ts b/src/activity/activity.gql.ts new file mode 100644 index 0000000..de3fc55 --- /dev/null +++ b/src/activity/activity.gql.ts @@ -0,0 +1,12 @@ +import { QuizlordContext } from '..'; +import { authorisationService, activityService } from '../service.locator'; + +async function activityFeed(_: unknown, _params: Record, context: QuizlordContext) { + authorisationService.requireUserRole(context, 'USER'); + + return activityService.getRecentActivity(); +} + +export const activityQueries = { + activityFeed, +}; diff --git a/src/gql.ts b/src/gql.ts index 4578759..57208d2 100644 --- a/src/gql.ts +++ b/src/gql.ts @@ -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 { """ @@ -166,6 +177,11 @@ const typeDefs = gql` "The sorting option to use" sortedBy: IndividualUserStatisticsSortOption ): [IndividualUserStatistic] + + """ + Get the most recent activities. + """ + activityFeed: [RecentActivityItem] } type Mutation { diff --git a/src/index.ts b/src/index.ts index b2b25c4..0553c29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -41,6 +42,7 @@ const resolvers = { ...quizQueries, ...userQueries, ...statisticsQueries, + ...activityQueries, }, Mutation: { ...quizMutations, diff --git a/src/service.locator.ts b/src/service.locator.ts index f52e3db..67065e1 100644 --- a/src/service.locator.ts +++ b/src/service.locator.ts @@ -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'; @@ -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);