refactor: replace all explicit any types with proper TypeScript types
Backend resolvers: typed enrichArticle/enrichVideo/enrichModel with DB and $inferSelect types, SQL<unknown>[] for conditions arrays, proper enum casts for status/role fields, $inferInsert for .set() updates, typed raw SQL result rows in gamification, ReplyLike interface for ctx.reply in auth. Frontend: typed catch blocks with Error/interface casts, isActiveLink param, adminGetUser response, tags filter callback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { GraphQLError } from "graphql";
|
||||
import { builder } from "../builder";
|
||||
import { CurrentUserType, UserType, AdminUserListType, AdminUserDetailType } from "../types/index";
|
||||
import { users, user_photos, files } from "../../db/schema/index";
|
||||
import { eq, ilike, or, count, and } from "drizzle-orm";
|
||||
import { eq, ilike, or, count, and, asc, type SQL } from "drizzle-orm";
|
||||
import { requireAdmin } from "../../lib/acl";
|
||||
|
||||
builder.queryField("me", (t) =>
|
||||
@@ -63,7 +63,7 @@ builder.mutationField("updateProfile", (t) =>
|
||||
|
||||
await ctx.db
|
||||
.update(users)
|
||||
.set(updates as any)
|
||||
.set(updates as Partial<typeof users.$inferInsert>)
|
||||
.where(eq(users.id, ctx.currentUser.id));
|
||||
|
||||
const updated = await ctx.db
|
||||
@@ -93,27 +93,27 @@ builder.queryField("adminListUsers", (t) =>
|
||||
const limit = args.limit ?? 50;
|
||||
const offset = args.offset ?? 0;
|
||||
|
||||
let query = ctx.db.select().from(users);
|
||||
let countQuery = ctx.db.select({ total: count() }).from(users);
|
||||
|
||||
const conditions: any[] = [];
|
||||
const conditions: SQL<unknown>[] = [];
|
||||
if (args.role) {
|
||||
conditions.push(eq(users.role, args.role as any));
|
||||
conditions.push(eq(users.role, args.role as "model" | "viewer" | "admin"));
|
||||
}
|
||||
if (args.search) {
|
||||
const pattern = `%${args.search}%`;
|
||||
conditions.push(or(ilike(users.email, pattern), ilike(users.artist_name, pattern)));
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
const where = conditions.length === 1 ? conditions[0] : and(...conditions);
|
||||
query = (query as any).where(where);
|
||||
countQuery = (countQuery as any).where(where);
|
||||
conditions.push(
|
||||
or(ilike(users.email, pattern), ilike(users.artist_name, pattern)) as SQL<unknown>,
|
||||
);
|
||||
}
|
||||
|
||||
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
||||
const [items, totalRows] = await Promise.all([
|
||||
(query as any).limit(limit).offset(offset),
|
||||
countQuery,
|
||||
ctx.db
|
||||
.select()
|
||||
.from(users)
|
||||
.where(where)
|
||||
.orderBy(asc(users.artist_name))
|
||||
.limit(limit)
|
||||
.offset(offset),
|
||||
ctx.db.select({ total: count() }).from(users).where(where),
|
||||
]);
|
||||
|
||||
return { items, total: totalRows[0]?.total ?? 0 };
|
||||
@@ -139,7 +139,8 @@ builder.mutationField("adminUpdateUser", (t) =>
|
||||
requireAdmin(ctx);
|
||||
|
||||
const updates: Record<string, unknown> = { date_updated: new Date() };
|
||||
if (args.role !== undefined && args.role !== null) updates.role = args.role as any;
|
||||
if (args.role !== undefined && args.role !== null)
|
||||
updates.role = args.role as "model" | "viewer" | "admin";
|
||||
if (args.isAdmin !== undefined && args.isAdmin !== null) updates.is_admin = args.isAdmin;
|
||||
if (args.firstName !== undefined && args.firstName !== null)
|
||||
updates.first_name = args.firstName;
|
||||
@@ -151,7 +152,7 @@ builder.mutationField("adminUpdateUser", (t) =>
|
||||
|
||||
const updated = await ctx.db
|
||||
.update(users)
|
||||
.set(updates as any)
|
||||
.set(updates as Partial<typeof users.$inferInsert>)
|
||||
.where(eq(users.id, args.userId))
|
||||
.returning();
|
||||
|
||||
@@ -194,8 +195,8 @@ builder.queryField("adminGetUser", (t) =>
|
||||
.orderBy(user_photos.sort);
|
||||
const seen = new Set<string>();
|
||||
const photos = photoRows
|
||||
.filter((p: any) => p.id && !seen.has(p.id) && seen.add(p.id))
|
||||
.map((p: any) => ({ id: p.id, filename: p.filename }));
|
||||
.filter((p) => p.id && !seen.has(p.id) && seen.add(p.id))
|
||||
.map((p) => ({ id: p.id, filename: p.filename }));
|
||||
return { ...user[0], photos };
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user