From 301a6b6cabc04e5d53ca2469e4c47c828ffee21b Mon Sep 17 00:00:00 2001 From: Carson Full Date: Fri, 4 Oct 2024 08:23:40 -0500 Subject: [PATCH 1/2] Notifications GQL schema (#3300) --- src/app.module.ts | 2 ++ src/components/notifications/dto/index.ts | 3 ++ .../dto/mark-notification-read.args.ts | 11 ++++++ .../dto/notification-list.input.ts | 26 ++++++++++++++ .../notifications/dto/notification.dto.ts | 35 +++++++++++++++++++ .../notifications/notification.module.ts | 7 ++++ .../notifications/notification.resolver.ts | 32 +++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 src/components/notifications/dto/index.ts create mode 100644 src/components/notifications/dto/mark-notification-read.args.ts create mode 100644 src/components/notifications/dto/notification-list.input.ts create mode 100644 src/components/notifications/dto/notification.dto.ts create mode 100644 src/components/notifications/notification.module.ts create mode 100644 src/components/notifications/notification.resolver.ts diff --git a/src/app.module.ts b/src/app.module.ts index ed334196fe..204134b85a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -18,6 +18,7 @@ import { FilmModule } from './components/film/film.module'; import { FundingAccountModule } from './components/funding-account/funding-account.module'; import { LanguageModule } from './components/language/language.module'; import { LocationModule } from './components/location/location.module'; +import { NotificationModule } from './components/notifications/notification.module'; import { OrganizationModule } from './components/organization/organization.module'; import { PartnerModule } from './components/partner/partner.module'; import { PartnershipProducingMediumModule } from './components/partnership-producing-medium/partnership-producing-medium.module'; @@ -89,6 +90,7 @@ if (process.env.NODE_ENV !== 'production') { ProgressReportModule, PromptsModule, PnpExtractionResultModule, + NotificationModule, ], }) export class AppModule {} diff --git a/src/components/notifications/dto/index.ts b/src/components/notifications/dto/index.ts new file mode 100644 index 0000000000..2d2b72fcd3 --- /dev/null +++ b/src/components/notifications/dto/index.ts @@ -0,0 +1,3 @@ +export * from './notification.dto'; +export * from './notification-list.input'; +export * from './mark-notification-read.args'; diff --git a/src/components/notifications/dto/mark-notification-read.args.ts b/src/components/notifications/dto/mark-notification-read.args.ts new file mode 100644 index 0000000000..4229090842 --- /dev/null +++ b/src/components/notifications/dto/mark-notification-read.args.ts @@ -0,0 +1,11 @@ +import { ArgsType, Field } from '@nestjs/graphql'; +import { ID, IdField } from '~/common'; + +@ArgsType() +export abstract class MarkNotificationReadArgs { + @IdField() + readonly id: ID<'Notification'>; + + @Field(() => Boolean, { nullable: true }) + readonly unread = false; +} diff --git a/src/components/notifications/dto/notification-list.input.ts b/src/components/notifications/dto/notification-list.input.ts new file mode 100644 index 0000000000..0ee1c5b701 --- /dev/null +++ b/src/components/notifications/dto/notification-list.input.ts @@ -0,0 +1,26 @@ +import { Field, InputType, Int, ObjectType } from '@nestjs/graphql'; +import { FilterField, PaginatedList, PaginationInput } from '~/common'; +import { Notification } from './notification.dto'; + +@InputType() +export abstract class NotificationFilters { + @Field(() => Boolean, { + description: 'Only read/unread notifications', + nullable: true, + }) + readonly unread?: boolean; +} + +@InputType() +export class NotificationListInput extends PaginationInput { + @FilterField(() => NotificationFilters) + readonly filter?: NotificationFilters; +} + +@ObjectType() +export class NotificationList extends PaginatedList(Notification) { + @Field(() => Int, { + description: 'The total number of unread notifications', + }) + readonly totalUnread: number; +} diff --git a/src/components/notifications/dto/notification.dto.ts b/src/components/notifications/dto/notification.dto.ts new file mode 100644 index 0000000000..db7bcb561c --- /dev/null +++ b/src/components/notifications/dto/notification.dto.ts @@ -0,0 +1,35 @@ +import { Field, InterfaceType, ObjectType } from '@nestjs/graphql'; +import { keys as keysOf } from 'ts-transformer-keys'; +import { Resource, SecuredProps } from '~/common'; +import { LinkTo, RegisterResource } from '~/core/resources'; + +@RegisterResource() +@InterfaceType({ + implements: [Resource], +}) +export class Notification extends Resource { + static readonly Props = keysOf(); + static readonly SecuredProps = keysOf>(); + + readonly owner: LinkTo<'User'>; + + @Field(() => Boolean) + readonly unread: boolean; +} + +@ObjectType({ + implements: [Notification], +}) +export class SimpleTextNotification extends Notification { + @Field(() => String) + readonly content: string; +} + +declare module '~/core/resources/map' { + interface ResourceMap { + Notification: typeof Notification; + } + // interface ResourceDBMap { + // Notification: typeof e.Notification; + // } +} diff --git a/src/components/notifications/notification.module.ts b/src/components/notifications/notification.module.ts new file mode 100644 index 0000000000..d4e9cb205f --- /dev/null +++ b/src/components/notifications/notification.module.ts @@ -0,0 +1,7 @@ +import { Module } from '@nestjs/common'; +import { NotificationResolver } from './notification.resolver'; + +@Module({ + providers: [NotificationResolver], +}) +export class NotificationModule {} diff --git a/src/components/notifications/notification.resolver.ts b/src/components/notifications/notification.resolver.ts new file mode 100644 index 0000000000..348d783e31 --- /dev/null +++ b/src/components/notifications/notification.resolver.ts @@ -0,0 +1,32 @@ +import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; +import { + ListArg, + LoggedInSession, + NotImplementedException, + Session, +} from '~/common'; +import { + MarkNotificationReadArgs, + Notification, + NotificationList, + NotificationListInput, +} from './dto'; + +@Resolver() +export class NotificationResolver { + @Query(() => NotificationList) + async notifications( + @LoggedInSession() session: Session, + @ListArg(NotificationListInput) input: NotificationListInput, + ): Promise { + throw new NotImplementedException().with(input, session); + } + + @Mutation(() => Notification) + async readNotification( + @LoggedInSession() session: Session, + @Args() input: MarkNotificationReadArgs, + ): Promise { + throw new NotImplementedException().with(input, session); + } +} From 0a751014890bae427b28cc75e4afdc005a0986b6 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Fri, 4 Oct 2024 08:47:11 -0500 Subject: [PATCH 2/2] Remove stray query log --- src/components/progress-report/progress-report.repository.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/progress-report/progress-report.repository.ts b/src/components/progress-report/progress-report.repository.ts index f63a92ec7a..dba930d186 100644 --- a/src/components/progress-report/progress-report.repository.ts +++ b/src/components/progress-report/progress-report.repository.ts @@ -42,7 +42,6 @@ export class ProgressReportRepository extends DtoRepository< relation('in', '', 'engagement'), node('project', 'Project'), ]) - .logIt() .match(requestingUser(session)) .apply(progressReportFilters(input.filter)) .apply(