feat: Introduce new modules for class, inventory, leveling, and quests with expanded schema, refactor user service, and add verification scripts.

This commit is contained in:
syntaxbullet
2025-12-07 23:03:33 +01:00
parent be471f348d
commit 29c0a4752d
21 changed files with 1228 additions and 163 deletions

View File

@@ -0,0 +1,44 @@
import { users } from "@/db/schema";
import { eq, sql } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient";
export const userService = {
getUserById: async (id: string) => {
const user = await DrizzleClient.query.users.findFirst({
where: eq(users.id, BigInt(id)),
with: { class: true }
});
return user;
},
getUserByUsername: async (username: string) => {
const user = await DrizzleClient.query.users.findFirst({ where: eq(users.username, username) });
return user;
},
createUser: async (id: string | bigint, username: string, classId?: bigint, tx?: any) => {
const execute = async (txFn: any) => {
const [user] = await txFn.insert(users).values({
id: BigInt(id),
username,
classId,
}).returning();
return user;
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
},
updateUser: async (id: string, data: Partial<typeof users.$inferInsert>, tx?: any) => {
const execute = async (txFn: any) => {
const [user] = await txFn.update(users)
.set(data)
.where(eq(users.id, BigInt(id)))
.returning();
return user;
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
},
deleteUser: async (id: string, tx?: any) => {
const execute = async (txFn: any) => {
await txFn.delete(users).where(eq(users.id, BigInt(id)));
};
return tx ? await execute(tx) : await DrizzleClient.transaction(execute);
},
};