docs: add JSDoc to service public methods
One-line JSDoc on 82 methods across 11 service files for quick scanning without reading full implementations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { withTransaction } from "@/lib/db";
|
||||
import type { Transaction } from "@shared/lib/types";
|
||||
|
||||
export const userService = {
|
||||
/** Fetch a user by Discord ID, including their class relation. */
|
||||
getUserById: async (id: string) => {
|
||||
const user = await DrizzleClient.query.users.findFirst({
|
||||
where: eq(users.id, BigInt(id)),
|
||||
@@ -12,10 +13,12 @@ export const userService = {
|
||||
});
|
||||
return user;
|
||||
},
|
||||
/** Fetch a user by their username. */
|
||||
getUserByUsername: async (username: string) => {
|
||||
const user = await DrizzleClient.query.users.findFirst({ where: eq(users.username, username) });
|
||||
return user;
|
||||
},
|
||||
/** Fetch a user by ID, creating a new record if one does not exist. */
|
||||
getOrCreateUser: async (id: string, username: string, tx?: Transaction) => {
|
||||
return await withTransaction(async (txFn) => {
|
||||
let user = await txFn.query.users.findFirst({
|
||||
@@ -38,6 +41,7 @@ export const userService = {
|
||||
return user;
|
||||
}, tx);
|
||||
},
|
||||
/** Get the class assigned to a user, or undefined if none. */
|
||||
getUserClass: async (id: string) => {
|
||||
const user = await DrizzleClient.query.users.findFirst({
|
||||
where: eq(users.id, BigInt(id)),
|
||||
@@ -45,6 +49,7 @@ export const userService = {
|
||||
});
|
||||
return user?.class;
|
||||
},
|
||||
/** Create a new user with an optional initial class assignment. */
|
||||
createUser: async (id: string | bigint, username: string, classId?: bigint, tx?: Transaction) => {
|
||||
return await withTransaction(async (txFn) => {
|
||||
const [user] = await txFn.insert(users).values({
|
||||
@@ -55,6 +60,7 @@ export const userService = {
|
||||
return user;
|
||||
}, tx);
|
||||
},
|
||||
/** Update a user record with partial data. */
|
||||
updateUser: async (id: string, data: Partial<typeof users.$inferInsert>, tx?: Transaction) => {
|
||||
return await withTransaction(async (txFn) => {
|
||||
const [user] = await txFn.update(users)
|
||||
@@ -64,6 +70,7 @@ export const userService = {
|
||||
return user;
|
||||
}, tx);
|
||||
},
|
||||
/** Delete a user by ID. */
|
||||
deleteUser: async (id: string, tx?: Transaction) => {
|
||||
return await withTransaction(async (txFn) => {
|
||||
await txFn.delete(users).where(eq(users.id, BigInt(id)));
|
||||
|
||||
Reference in New Issue
Block a user