-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-snippet.ts
31 lines (26 loc) · 1004 Bytes
/
create-snippet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { CreateSnippetDto } from '@sharingan/domain';
import { getAuthenticatedUser } from '../../../configs/authentication';
import { logger } from '../../../configs/logger';
import { MutationResolvers } from '../../../types/graphql';
import { throwApplicationError } from '../../../utils/errors/throw-error';
export const createSnippet: MutationResolvers['createSnippet'] = async (_parent, { input }, context) => {
const userId = getAuthenticatedUser(context);
const createSnippetDto = new CreateSnippetDto({
content: input.content,
contentHighlighted: input.contentHighlighted,
description: input.description ?? null,
folderId: input.folderId,
language: input.language,
lineHighlight: input.lineHighlight ?? null,
name: input.name,
theme: input.theme,
userId,
visibility: input.visibility,
});
try {
return context.db.snippet.create(createSnippetDto);
} catch (err: any) {
logger.error(err);
return throwApplicationError(err);
}
};