-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-snippet.ts
31 lines (26 loc) · 1008 Bytes
/
update-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 { UpdateSnippetDto } 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 updateSnippet: MutationResolvers['updateSnippet'] = async (_parent, { id, input }, context) => {
const userId = getAuthenticatedUser(context);
const updateSnippetDto = new UpdateSnippetDto({
content: input.content,
contentHighlighted: input.contentHighlighted,
creatorId: userId,
description: input.description ?? null,
language: input.language,
lineHighlight: input.lineHighlight ?? null,
name: input.name,
snippetId: id,
theme: input.theme,
visibility: input.visibility,
});
try {
return context.db.snippet.update(updateSnippetDto);
} catch (err: any) {
logger.error(err);
return throwApplicationError(err);
}
};