feat: Implement custom error classes, a Drizzle transaction utility, and update Discord.js ephemeral message flags.

This commit is contained in:
syntaxbullet
2025-12-15 22:14:17 +01:00
parent 3c81fd8396
commit 7e986fae5a
14 changed files with 112 additions and 114 deletions

View File

@@ -4,10 +4,12 @@ import { eq, and, sql } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient";
import { economyService } from "@/modules/economy/economy.service";
import { levelingService } from "@/modules/leveling/leveling.service";
import { withTransaction } from "@/lib/db";
import type { Transaction } from "@/lib/types";
export const questService = {
assignQuest: async (userId: string, questId: number, tx?: any) => {
const execute = async (txFn: any) => {
assignQuest: async (userId: string, questId: number, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
return await txFn.insert(userQuests)
.values({
userId: BigInt(userId),
@@ -16,12 +18,11 @@ export const questService = {
})
.onConflictDoNothing() // Ignore if already assigned
.returning();
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
}, tx);
},
updateProgress: async (userId: string, questId: number, progress: number, tx?: any) => {
const execute = async (txFn: any) => {
updateProgress: async (userId: string, questId: number, progress: number, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
return await txFn.update(userQuests)
.set({ progress: progress })
.where(and(
@@ -29,12 +30,11 @@ export const questService = {
eq(userQuests.questId, questId)
))
.returning();
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
}, tx);
},
completeQuest: async (userId: string, questId: number, tx?: any) => {
const execute = async (txFn: any) => {
completeQuest: async (userId: string, questId: number, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
const userQuest = await txFn.query.userQuests.findFirst({
where: and(
eq(userQuests.userId, BigInt(userId)),
@@ -73,9 +73,7 @@ export const questService = {
}
return { success: true, rewards: results };
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
}, tx);
},
getUserQuests: async (userId: string) => {