|
1 | 1 | import { PrismaClient } from '@prisma/client'; |
2 | 2 |
|
3 | | -const db = new PrismaClient({ |
| 3 | +export const db = new PrismaClient({ |
4 | 4 | errorFormat: 'pretty' |
5 | 5 | }); |
6 | 6 |
|
7 | | -export const createTag = async (trigger: string, content: string) => { |
8 | | - return db.tag.create({ |
| 7 | +export const createTag = async (guildId: string, authorId: string, trigger: string, content: string) => { |
| 8 | + return await db.tag.create({ |
9 | 9 | data: { |
| 10 | + guildId, |
| 11 | + authorId, |
10 | 12 | trigger, |
11 | | - content |
| 13 | + content, |
| 14 | + lastEditedById: authorId |
12 | 15 | } |
13 | 16 | }); |
14 | 17 | }; |
15 | 18 |
|
16 | 19 | export const getTag = async (tagId: string) => { |
17 | | - return db.tag.findUnique({ |
| 20 | + return await db.tag.findUnique({ |
18 | 21 | where: { |
19 | 22 | id: tagId |
20 | 23 | } |
21 | 24 | }); |
22 | 25 | }; |
23 | 26 |
|
24 | 27 | export const getTagByTrigger = async (trigger: string) => { |
25 | | - return db.tag.findFirst({ |
| 28 | + return await db.tag.findFirst({ |
26 | 29 | where: { |
27 | 30 | trigger |
28 | 31 | } |
29 | 32 | }); |
30 | 33 | }; |
31 | 34 |
|
32 | | -export const getAllTags = async () => { |
33 | | - return db.tag.findMany(); |
| 35 | +export const getAllTags = async (guildId: string) => { |
| 36 | + return await db.tag.findMany({ |
| 37 | + where: { |
| 38 | + guildId |
| 39 | + } |
| 40 | + }); |
34 | 41 | }; |
35 | 42 |
|
36 | | -export const editTag = async (tagId: string, trigger: string, content: string) => { |
37 | | - return db.tag.update({ |
| 43 | +export const editTag = async (tagId: string, editorId: string, trigger: string, content: string) => { |
| 44 | + return await db.tag.update({ |
38 | 45 | where: { |
39 | 46 | id: tagId |
40 | 47 | }, |
41 | 48 | data: { |
| 49 | + lastEditedById: editorId, |
| 50 | + lastEditedAt: new Date(), |
42 | 51 | trigger, |
43 | 52 | content |
44 | 53 | } |
45 | 54 | }); |
46 | 55 | }; |
47 | 56 |
|
48 | 57 | export const deleteTag = async (tagId: string) => { |
49 | | - return db.tag.delete({ |
| 58 | + return await db.tag.delete({ |
50 | 59 | where: { |
51 | 60 | id: tagId |
52 | 61 | } |
53 | 62 | }); |
54 | 63 | }; |
55 | 64 |
|
56 | 65 | export const incrementTagUses = async (tagId: string) => { |
57 | | - return db.tag.update({ |
| 66 | + return await db.tag.update({ |
58 | 67 | where: { |
59 | 68 | id: tagId |
60 | 69 | }, |
61 | 70 | data: { |
62 | 71 | uses: { |
63 | 72 | increment: 1 |
64 | | - } |
| 73 | + }, |
| 74 | + lastUsed: new Date() |
65 | 75 | } |
66 | 76 | }); |
67 | 77 | }; |
0 commit comments