-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote.server.ts
58 lines (53 loc) · 1.34 KB
/
note.server.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { scopedDb } from "~/db";
import e from "~/db/edgeql";
export const searchNotes = (clerkId: string, query: string) =>
e
.select(e.Note, (note) => ({
id: true,
name: true,
description: true,
filter: e.set(
e.op(note.name, "ilike", `%${query}%`),
e.op(note.description, "ilike", `%${query}%`)
),
}))
.run(scopedDb(clerkId));
export const getNote = (noteId: string, clerkId: string) =>
e
.select(e.Note, (note) => ({
id: true,
name: true,
description: true,
filter: e.op(note.id, "=", e.uuid(noteId)),
}))
.run(scopedDb(clerkId));
export const createNote = (
name: string,
description: string,
clerkId: string
) =>
e
.insert(e.Note, {
name,
description,
author: e.select(e.User, (user) => ({
filter: e.op(user.clerk_id, "=", clerkId),
})),
})
.run(scopedDb(clerkId));
export const updateNote = (
noteId: string,
name: string,
description: string,
clerkId: string
) =>
e
.update(e.Note, (note) => ({
filter: e.op(note.id, "=", e.uuid(noteId)),
set: { name, description },
}))
.run(scopedDb(clerkId));
export const deleteNote = (noteId: string, clerkId: string) =>
e
.delete(e.Note, (note) => ({ filter: e.op(note.id, "=", e.uuid(noteId)) }))
.run(scopedDb(clerkId));