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:
syntaxbullet
2026-04-02 11:36:18 +02:00
parent 5f8819bb46
commit 5bd390b4ee
11 changed files with 82 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ import { TransactionType } from "@shared/lib/constants";
export const inventoryService = {
/** Add items to a user's inventory; enforces max stack size and max slot limits. */
addItem: async (userId: string, itemId: number, quantity: bigint = 1n, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
// Check if item exists in inventory
@@ -74,6 +75,7 @@ export const inventoryService = {
}, tx);
},
/** Remove items from a user's inventory; deletes the entry if quantity reaches zero. */
removeItem: async (userId: string, itemId: number, quantity: bigint = 1n, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
const existing = await txFn.query.inventory.findFirst({
@@ -110,6 +112,7 @@ export const inventoryService = {
}, tx);
},
/** Retrieve all inventory entries for a user, including item details. */
getInventory: async (userId: string) => {
return await DrizzleClient.query.inventory.findMany({
where: eq(inventory.userId, BigInt(userId)),
@@ -119,6 +122,7 @@ export const inventoryService = {
});
},
/** Purchase an item from the shop; deducts balance and adds to inventory atomically. */
buyItem: async (userId: string, itemId: number, quantity: bigint = 1n, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
const item = await txFn.query.items.findFirst({
@@ -139,12 +143,14 @@ export const inventoryService = {
}, tx);
},
/** Fetch a single item definition by ID. */
getItem: async (itemId: number) => {
return await DrizzleClient.query.items.findFirst({
where: eq(items.id, itemId),
});
},
/** Use a consumable item, applying its effects and consuming it if configured. */
useItem: async (userId: string, itemId: number, tx?: Transaction) => {
return await withTransaction(async (txFn) => {
// 1. Check Ownership & Quantity
@@ -189,6 +195,7 @@ export const inventoryService = {
}, tx);
},
/** Search a user's usable inventory items by name for autocomplete suggestions. */
getAutocompleteItems: async (userId: string, query: string) => {
const entries = await DrizzleClient.select({
quantity: inventory.quantity,