MCPcopy
hub / github.com/Peppermint-Lab/peppermint / notebookRoutes

Function notebookRoutes

apps/api/src/controllers/notebook.ts:19–132  ·  view source on GitHub ↗
(fastify: FastifyInstance)

Source from the content-addressed store, hash-verified

17}
18
19export function notebookRoutes(fastify: FastifyInstance) {
20 // Create a new entry
21 fastify.post(
22 "/api/v1/notebook/note/create",
23 {
24 preHandler: requirePermission(["document::create"]),
25 },
26 async (request: FastifyRequest, reply: FastifyReply) => {
27 const { content, title }: any = request.body;
28 const user = await checkSession(request);
29
30 const data = await prisma.notes.create({
31 data: {
32 title,
33 note: content,
34 userId: user!.id,
35 },
36 });
37
38 await tracking("note_created", {});
39
40 const { id } = data;
41
42 reply.status(200).send({ success: true, id });
43 }
44 );
45
46 // Get all entries
47 fastify.get(
48 "/api/v1/notebooks/all",
49 {
50 preHandler: requirePermission(["document::read"]),
51 },
52 async (request: FastifyRequest, reply: FastifyReply) => {
53 const user = await checkSession(request);
54
55 const notebooks = await prisma.notes.findMany({
56 where: { userId: user!.id },
57 });
58
59 reply.status(200).send({ success: true, notebooks: notebooks });
60 }
61 );
62
63 // Get a single entry
64 fastify.get(
65 "/api/v1/notebooks/note/:id",
66 {
67 preHandler: requirePermission(["document::read"]),
68 },
69 async (request: FastifyRequest, reply: FastifyReply) => {
70 const user = await checkSession(request);
71
72 const { id }: any = request.params;
73
74 const note = await prisma.notes.findUnique({
75 where: { userId: user!.id, id: id },
76 });

Callers 1

registerRoutesFunction · 0.90

Calls 3

requirePermissionFunction · 0.90
checkSessionFunction · 0.90
trackingFunction · 0.70

Tested by

no test coverage detected