统一前后端代码格式化配置
This commit is contained in:
@@ -20,10 +20,12 @@ type AdminUserCreateInput = {
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
type AdminUserPatch = Partial<Pick<
|
||||
AdminUserRow,
|
||||
'username' | 'password_hash' | 'role' | 'status' | 'session_version' | 'updated_at'
|
||||
>>
|
||||
type AdminUserPatch = Partial<
|
||||
Pick<
|
||||
AdminUserRow,
|
||||
'username' | 'password_hash' | 'role' | 'status' | 'session_version' | 'updated_at'
|
||||
>
|
||||
>
|
||||
|
||||
type AdminUserListInput = {
|
||||
page?: number
|
||||
@@ -44,23 +46,23 @@ const ADMIN_USER_SELECT = `
|
||||
`
|
||||
|
||||
export async function getAdminUserById(userId: number | string): Promise<AdminUserRow | null> {
|
||||
const result = await query<AdminUserRow>(
|
||||
`${ADMIN_USER_SELECT} WHERE au.id = $1 LIMIT 1`,
|
||||
[Number(userId)],
|
||||
)
|
||||
const result = await query<AdminUserRow>(`${ADMIN_USER_SELECT} WHERE au.id = $1 LIMIT 1`, [
|
||||
Number(userId),
|
||||
])
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function getAdminUserByUsername(username: string): Promise<AdminUserRow | null> {
|
||||
const result = await query<AdminUserRow>(
|
||||
`${ADMIN_USER_SELECT} WHERE au.username = $1 LIMIT 1`,
|
||||
[String(username || '').trim().toLowerCase()],
|
||||
)
|
||||
const result = await query<AdminUserRow>(`${ADMIN_USER_SELECT} WHERE au.username = $1 LIMIT 1`, [
|
||||
String(username || '')
|
||||
.trim()
|
||||
.toLowerCase(),
|
||||
])
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function createAdminUser(input: AdminUserCreateInput): Promise<AdminUserRow | null> {
|
||||
const result = await query<{ [column: string]: unknown, id: number }>(
|
||||
const result = await query<{ [column: string]: unknown; id: number }>(
|
||||
`
|
||||
INSERT INTO admin_users (
|
||||
username,
|
||||
@@ -97,7 +99,7 @@ export async function updateAdminUser(
|
||||
}
|
||||
|
||||
const next = { ...current, ...patch }
|
||||
const result = await query<{ [column: string]: unknown, id: number }>(
|
||||
const result = await query<{ [column: string]: unknown; id: number }>(
|
||||
`
|
||||
UPDATE admin_users
|
||||
SET
|
||||
@@ -151,7 +153,7 @@ export async function listAdminUsers({
|
||||
}
|
||||
|
||||
const whereClause = filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : ''
|
||||
const totalResult = await query<{ [column: string]: unknown, total: number }>(
|
||||
const totalResult = await query<{ [column: string]: unknown; total: number }>(
|
||||
`SELECT COUNT(*)::int AS total FROM admin_users ${whereClause}`,
|
||||
params,
|
||||
)
|
||||
@@ -175,7 +177,7 @@ export async function listAdminUsers({
|
||||
}
|
||||
|
||||
export async function countActiveAdminUsers(): Promise<number> {
|
||||
const result = await query<{ [column: string]: unknown, total: number }>(
|
||||
const result = await query<{ [column: string]: unknown; total: number }>(
|
||||
`SELECT COUNT(*)::int AS total FROM admin_users WHERE role = 'admin' AND status = 'active'`,
|
||||
)
|
||||
return Number(result.rows[0]?.total || 0)
|
||||
|
||||
Reference in New Issue
Block a user