Skip to content

Commit 60215db

Browse files
committed
Change SystemNotification message type: String -> Markdown
1 parent e14fb7d commit 60215db

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/common/markdown.scalar.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { CustomScalar, Scalar } from '@nestjs/graphql';
22
import { GraphQLError, Kind, ValueNode } from 'graphql';
33

4-
@Scalar('InlineMarkdown')
5-
export class InlineMarkdownScalar
6-
implements CustomScalar<string, string | null>
7-
{
8-
description = 'A string that holds inline Markdown formatted text';
4+
@Scalar('Markdown')
5+
export class MarkdownScalar implements CustomScalar<string, string | null> {
6+
description = 'A string that holds Markdown formatted text';
97

108
parseLiteral(ast: ValueNode): string | null {
119
if (ast.kind !== Kind.STRING) {
@@ -22,3 +20,8 @@ export class InlineMarkdownScalar
2220
return value;
2321
}
2422
}
23+
24+
@Scalar('InlineMarkdown')
25+
export class InlineMarkdownScalar extends MarkdownScalar {
26+
description = 'A string that holds inline Markdown formatted text';
27+
}

src/common/scalars.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CustomScalar } from '@nestjs/graphql';
33
import { GraphQLScalarType } from 'graphql';
44
import UploadScalar from 'graphql-upload/GraphQLUpload.mjs';
55
import { DateScalar, DateTimeScalar } from './luxon.graphql';
6-
import { InlineMarkdownScalar } from './markdown.scalar';
6+
import { InlineMarkdownScalar, MarkdownScalar } from './markdown.scalar';
77
import { RichTextScalar } from './rich-text.scalar';
88
import { UrlScalar } from './url.field';
99

@@ -16,5 +16,6 @@ export const getRegisteredScalars = (): Scalar[] => [
1616
RichTextScalar,
1717
UploadScalar,
1818
UrlScalar,
19+
MarkdownScalar,
1920
InlineMarkdownScalar,
2021
];

src/components/notification-system/system-notification.dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Field, ObjectType } from '@nestjs/graphql';
22
import { keys as keysOf } from 'ts-transformer-keys';
33
import { SecuredProps } from '~/common';
4+
import { MarkdownScalar } from '~/common/markdown.scalar';
45
import { Notification } from '../notifications';
56

67
@ObjectType({
@@ -10,6 +11,6 @@ export class SystemNotification extends Notification {
1011
static readonly Props = keysOf<SystemNotification>();
1112
static readonly SecuredProps = keysOf<SecuredProps<SystemNotification>>();
1213

13-
@Field()
14+
@Field(() => MarkdownScalar)
1415
readonly message: string;
1516
}

src/components/notification-system/system-notification.resolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Resolver,
88
} from '@nestjs/graphql';
99
import { ID, LoggedInSession, Session, UnauthorizedException } from '~/common';
10+
import { MarkdownScalar } from '~/common/markdown.scalar';
1011
import { isAdmin } from '~/common/session';
1112
import { NotificationService } from '../notifications';
1213
import { SystemNotification } from './system-notification.dto';
@@ -26,7 +27,7 @@ export class SystemNotificationResolver {
2627

2728
@Mutation(() => SystemNotificationCreationOutput)
2829
async createSystemNotification(
29-
@Args('message') message: string,
30+
@Args({ name: 'message', type: () => MarkdownScalar }) message: string,
3031
@LoggedInSession() session: Session,
3132
): Promise<SystemNotificationCreationOutput> {
3233
if (!isAdmin(session)) {

0 commit comments

Comments
 (0)