Moved all db logic to db functions

This commit is contained in:
2024-10-25 19:52:34 +02:00
parent d206703098
commit f2aa84f8a5
28 changed files with 244 additions and 73 deletions

View File

@@ -1,5 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, GuildMember, TextChannel } from "discord.js"
import db from "src/drizzle/db.js"
import { addStaffApp, getSetting, getStaffApp } from "src/drizzle/functions"
import { staffApps } from "src/drizzle/schema.js"
import { ignM, largeM } from "~/config/limitmessages.js"
import { embedColor, staffApplicationsChannel } from "~/config/options.js"
@@ -17,9 +18,7 @@ export default {
const user = interaction.member as GuildMember
const guild = interaction.guild!
const userRoles = user.roles.cache
const setting = await db.query.settings.findFirst({
where: ({ name }, { eq }) => eq(name, "staffApplications")
})
const setting = await getSetting({ name: "staffapplications" })
const status = setting?.value || "0"
function sq(n: number): string {
@@ -50,9 +49,7 @@ export default {
return
}
const application = await db.query.staffApps.findFirst({
where: ({ userID }, { eq }) => eq(userID, user.user.id)
})
const application = await getStaffApp({ userID: user.user.id })
if (application) {
await interaction.editReply("You already have an application in progress.")
@@ -225,7 +222,7 @@ export default {
}]
})
await db.insert(staffApps).values({
await addStaffApp({
userID: user.user.id,
uuid: uuid
})