refactor(db): typed query helpers, shared test FormData helper
Replace raw db.execute tuple casts with queryRows/rowsFrom/execResult/ affectedRows helpers from lib/db, drop redundant mysql2 casts on typed query builders, and centralize per-test fakeForm into test/fake-form. Update db mocks in tests so helpers resolve against mocked execute.
This commit is contained in:
1 parent
2e25b39364
commit
8638e81444
116 files changed
+866
-897
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { sql } from "drizzle-orm";
|
||||
import { checkLogin } from "@/lib/auth/password";
|
||||
import { cachedQuery, invalidateKey } from "@/lib/cached-db";
|
||||
import { db } from "@/lib/db";
|
||||
import { queryRows } from "@/lib/db";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
export interface LoginUser {
|
||||
@@ -45,7 +45,7 @@ export async function getLoginUser(
|
||||
return cachedQuery<LoginUser | null>(
|
||||
`login:user:${username}`,
|
||||
async () => {
|
||||
const [result] = await db.execute<{
|
||||
const rows = await queryRows<{
|
||||
id: number;
|
||||
username: string;
|
||||
password: string | null;
|
||||
@@ -63,16 +63,6 @@ export async function getLoginUser(
|
||||
WHERE username = ${username}
|
||||
LIMIT 1
|
||||
`);
|
||||
const rows = result as unknown as Array<{
|
||||
id: number;
|
||||
username: string;
|
||||
password: string | null;
|
||||
rank: number;
|
||||
mail: string | null;
|
||||
mail_verified: string | null;
|
||||
two_factor_confirmed_at: string | null;
|
||||
two_factor_secret: string | null;
|
||||
}>;
|
||||
return rows.length > 0
|
||||
? {
|
||||
id: rows[0].id,
|
||||
|
||||
Reference in new issue
Block a user