-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete-snippet.ts
25 lines (19 loc) · 737 Bytes
/
delete-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
import { DeleteSnippetDto } from '@snipcode/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 deleteSnippet: MutationResolvers['deleteSnippet'] = async (_parent, { id }, context) => {
const userId = getAuthenticatedUser(context);
const deleteSnippetDto = new DeleteSnippetDto({
creatorId: userId,
snippetId: id,
});
try {
await context.db.snippet.delete(deleteSnippetDto);
return true;
} catch (err: any) {
logger.error(err);
return throwApplicationError(err);
}
};