Moved all db logic to db functions
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, TextChannel } from "discord.js"
|
||||
import { eq } from "drizzle-orm"
|
||||
import db from "src/drizzle/db.js"
|
||||
import { getGuildApp, removeVerify } from "src/drizzle/functions"
|
||||
import { addWaitingList, getWaitingLists, removeWaitingList } from "src/drizzle/functions"
|
||||
import { guildApps, waitingLists } from "src/drizzle/schema.js"
|
||||
import { embedColor, hypixelGuildID, waitingListChannel, waitingListMessage } from "~/config/options.js"
|
||||
import { waitingListRole } from "~/config/roles.js"
|
||||
@@ -54,20 +56,18 @@ export default {
|
||||
}]
|
||||
})
|
||||
|
||||
const applicantEntry = await db.query.guildApps.findFirst({
|
||||
where: ({ userID }, { eq }) => eq(userID, applicantId)
|
||||
})
|
||||
const applicantEntry = await getGuildApp({ userID: applicantId })
|
||||
const applicantUUID = applicantEntry!.uuid
|
||||
const time = Date.now()
|
||||
|
||||
await db.insert(waitingLists).values({
|
||||
await addWaitingList({
|
||||
userID: applicantId,
|
||||
uuid: applicantUUID,
|
||||
timestamp: time
|
||||
})
|
||||
|
||||
await applicant.roles.add(waitingListRole)
|
||||
await db.delete(guildApps).where(eq(guildApps.userID, applicantId))
|
||||
await removeVerify({ userID: applicantId })
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
@@ -90,14 +90,14 @@ export default {
|
||||
const wlmessage = await channel!.messages.fetch(waitingListMessage)
|
||||
|
||||
const wlembed = wlmessage.embeds[0]
|
||||
const accepted = await db.query.waitingLists.findMany()
|
||||
const accepted = await getWaitingLists()
|
||||
|
||||
for (let i = 0; i < accepted.length; i++) {
|
||||
const uuid = accepted[i].uuid
|
||||
const guild = await getGuild(uuid)
|
||||
|
||||
if (guild && guild._id === hypixelGuildID) {
|
||||
await db.delete(waitingLists).where(eq(waitingLists.uuid, uuid))
|
||||
await removeWaitingList({ uuid })
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user