提交正式官网
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { queryOne } from './mysql'
|
||||
|
||||
export type AdminUserRow = {
|
||||
id: number
|
||||
username: string
|
||||
password: string
|
||||
name: string | null
|
||||
avatar: string | null
|
||||
phone: string | null
|
||||
email: string | null
|
||||
role_id: number | null
|
||||
status: string
|
||||
is_built_in: number
|
||||
bio: string | null
|
||||
tags: string | null
|
||||
create_time: string
|
||||
update_time: string
|
||||
}
|
||||
|
||||
export type AdminRoleRow = {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
description: string | null
|
||||
is_built_in: number
|
||||
status: string
|
||||
menu_ids: string
|
||||
create_time: string
|
||||
update_time: string
|
||||
}
|
||||
|
||||
export function rowToUser(row: AdminUserRow) {
|
||||
return {
|
||||
id: String(row.id),
|
||||
username: row.username,
|
||||
password: row.password,
|
||||
name: row.name ?? undefined,
|
||||
avatar: row.avatar ?? undefined,
|
||||
phone: row.phone ?? undefined,
|
||||
email: row.email ?? undefined,
|
||||
roleId: row.role_id != null ? String(row.role_id) : undefined,
|
||||
status: row.status as 'active' | 'inactive',
|
||||
isBuiltIn: row.is_built_in === 1,
|
||||
bio: row.bio ?? undefined,
|
||||
tags: row.tags ?? undefined,
|
||||
createTime: row.create_time,
|
||||
updateTime: row.update_time,
|
||||
}
|
||||
}
|
||||
|
||||
export function rowToRole(row: AdminRoleRow) {
|
||||
return {
|
||||
id: String(row.id),
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
description: row.description ?? undefined,
|
||||
isBuiltIn: row.is_built_in === 1,
|
||||
status: row.status as 'active' | 'inactive',
|
||||
menuIds: JSON.parse(row.menu_ids || '[]') as string[],
|
||||
createTime: row.create_time,
|
||||
updateTime: row.update_time,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserById(id: string | number) {
|
||||
const row = await queryOne<AdminUserRow>('SELECT * FROM admin_users WHERE id = ?', [id])
|
||||
return row ? rowToUser(row) : null
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username: string) {
|
||||
const row = await queryOne<AdminUserRow>('SELECT * FROM admin_users WHERE username = ?', [username])
|
||||
return row ? rowToUser(row) : null
|
||||
}
|
||||
|
||||
export async function getRoleById(id: string | number) {
|
||||
const row = await queryOne<AdminRoleRow>('SELECT * FROM admin_roles WHERE id = ?', [id])
|
||||
return row ? rowToRole(row) : null
|
||||
}
|
||||
Reference in New Issue
Block a user