From 26a012d62efd167216d90cdf4212acbf19d5836d Mon Sep 17 00:00:00 2001 From: QuantCode Agent Date: Fri, 29 May 2026 01:59:51 +0000 Subject: [PATCH] fix: resolve all test failures and type errors across api and shared packages - Fix auth middleware case-sensitivity bug (HTTP methods must be uppercase) - Fix User type field name: userName -> username to match test expectations - Add missing badRequest helper and fix field references in users route - Implement pagination utility (paginate function) in shared package - Add process type declaration in auth.ts to resolve TS2580 --- packages/api/src/middleware/auth.ts | 4 +++- packages/api/src/routes/users.ts | 5 +---- packages/shared/src/types.ts | 2 +- packages/shared/src/utils/pagination.ts | 6 +++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/api/src/middleware/auth.ts b/packages/api/src/middleware/auth.ts index dde32d9..544b3c1 100644 --- a/packages/api/src/middleware/auth.ts +++ b/packages/api/src/middleware/auth.ts @@ -1,3 +1,5 @@ +declare const process: { env: Record } + import type { MiddlewareHandler } from "hono" /** @@ -15,7 +17,7 @@ import type { MiddlewareHandler } from "hono" */ export const authMiddleware: MiddlewareHandler = async (c, next) => { // BUG: 'post' should be 'POST' — POST is never treated as public - const publicMethods = ["GET", "post"] + const publicMethods = ["GET", "POST"] if (publicMethods.includes(c.req.method)) { return next() diff --git a/packages/api/src/routes/users.ts b/packages/api/src/routes/users.ts index 53e605a..ea4702a 100644 --- a/packages/api/src/routes/users.ts +++ b/packages/api/src/routes/users.ts @@ -1,9 +1,6 @@ import { Hono } from "hono" import { db } from "../lib/db" -import { notFound } from "../lib/errors" -// BUG: missing import — `badRequest` is used below but not imported here. -// This causes a ReferenceError at runtime when POST /users is called with invalid data. -// Fix: add `badRequest` to the import from "../lib/errors" +import { notFound, badRequest } from "../lib/errors" const router = new Hono() diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts index a2a1377..d522b01 100644 --- a/packages/shared/src/types.ts +++ b/packages/shared/src/types.ts @@ -8,7 +8,7 @@ export type User = { id: string - userName: string // BUG: should be `username` to match API usage + username: string email: string createdAt: string } diff --git a/packages/shared/src/utils/pagination.ts b/packages/shared/src/utils/pagination.ts index 12f8062..3c5f182 100644 --- a/packages/shared/src/utils/pagination.ts +++ b/packages/shared/src/utils/pagination.ts @@ -11,5 +11,9 @@ import type { PaginatedResponse } from "../types" * The test in packages/shared/test/pagination.test.ts exercises the full contract. */ export function paginate(items: T[], page: number, size: number): PaginatedResponse { - throw new Error("not implemented") + const total = items.length + const totalPages = total === 0 ? 0 : Math.ceil(total / size) + const start = (page - 1) * size + const data = items.slice(start, start + size) + return { data, page, pageSize: size, total, totalPages } }