-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
97 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,77 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
const db = new PrismaClient({ | ||
export const db = new PrismaClient({ | ||
errorFormat: 'pretty' | ||
}); | ||
|
||
export const createTag = async (trigger: string, content: string) => { | ||
return db.tag.create({ | ||
export const createTag = async (guildId: string, authorId: string, trigger: string, content: string) => { | ||
return await db.tag.create({ | ||
data: { | ||
guildId, | ||
authorId, | ||
trigger, | ||
content | ||
content, | ||
lastEditedById: authorId | ||
} | ||
}); | ||
}; | ||
|
||
export const getTag = async (tagId: string) => { | ||
return db.tag.findUnique({ | ||
return await db.tag.findUnique({ | ||
where: { | ||
id: tagId | ||
} | ||
}); | ||
}; | ||
|
||
export const getTagByTrigger = async (trigger: string) => { | ||
return db.tag.findFirst({ | ||
return await db.tag.findFirst({ | ||
where: { | ||
trigger | ||
} | ||
}); | ||
}; | ||
|
||
export const getAllTags = async () => { | ||
return db.tag.findMany(); | ||
export const getAllTags = async (guildId: string) => { | ||
return await db.tag.findMany({ | ||
where: { | ||
guildId | ||
} | ||
}); | ||
}; | ||
|
||
export const editTag = async (tagId: string, trigger: string, content: string) => { | ||
return db.tag.update({ | ||
export const editTag = async (tagId: string, editorId: string, trigger: string, content: string) => { | ||
return await db.tag.update({ | ||
where: { | ||
id: tagId | ||
}, | ||
data: { | ||
lastEditedById: editorId, | ||
lastEditedAt: new Date(), | ||
trigger, | ||
content | ||
} | ||
}); | ||
}; | ||
|
||
export const deleteTag = async (tagId: string) => { | ||
return db.tag.delete({ | ||
return await db.tag.delete({ | ||
where: { | ||
id: tagId | ||
} | ||
}); | ||
}; | ||
|
||
export const incrementTagUses = async (tagId: string) => { | ||
return db.tag.update({ | ||
return await db.tag.update({ | ||
where: { | ||
id: tagId | ||
}, | ||
data: { | ||
uses: { | ||
increment: 1 | ||
} | ||
}, | ||
lastUsed: new Date() | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters