83 lines
2.2 KiB
Plaintext
83 lines
2.2 KiB
Plaintext
import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'
|
|
|
|
export type AdminUserLabel = {
|
|
id: string
|
|
name: string
|
|
color: string | null
|
|
remark: string | null
|
|
status: number
|
|
created_at: string | null
|
|
updated_at: string | null
|
|
deleted_at: string | null
|
|
}
|
|
|
|
export type AdminUserLabelPageResult = {
|
|
total: number
|
|
items: Array<AdminUserLabel>
|
|
}
|
|
|
|
export type AdminUserLabelPageFilters = {
|
|
search?: string | null
|
|
status?: number | null
|
|
includeDeleted?: boolean
|
|
}
|
|
|
|
export async function fetchAdminUserLabelPage(
|
|
page: number,
|
|
pageSize: number,
|
|
filters: AdminUserLabelPageFilters = {}
|
|
): Promise<AdminUserLabelPageResult> {
|
|
const res = await rpcOrNull('rpc_admin_user_label_list', {
|
|
p_page: page,
|
|
p_page_size: pageSize,
|
|
p_search: filters.search ?? null,
|
|
p_status: filters.status ?? null,
|
|
p_include_deleted: filters.includeDeleted ?? false
|
|
} as any)
|
|
|
|
if (res == null) return { total: 0, items: [] as Array<AdminUserLabel> }
|
|
|
|
const anyTotal = (res as any).total
|
|
const anyItems = (res as any).items
|
|
|
|
const total = typeof anyTotal === 'number' ? anyTotal : parseInt(String(anyTotal ?? '0'))
|
|
const items = Array.isArray(anyItems) ? (anyItems as Array<any>) : ([] as Array<any>)
|
|
|
|
return { total, items: items as Array<AdminUserLabel> }
|
|
}
|
|
|
|
export type SaveAdminUserLabelInput = {
|
|
id?: string | null
|
|
name: string
|
|
color?: string | null
|
|
remark?: string | null
|
|
status?: number
|
|
}
|
|
|
|
export async function saveAdminUserLabel(input: SaveAdminUserLabelInput): Promise<string | null> {
|
|
const res = await rpcOrValue('rpc_admin_user_label_save', {
|
|
p_id: input.id ?? null,
|
|
p_name: input.name,
|
|
p_color: input.color ?? null,
|
|
p_remark: input.remark ?? null,
|
|
p_status: input.status ?? 1
|
|
} as any)
|
|
|
|
return res != null ? String(res) : null
|
|
}
|
|
|
|
export async function deleteAdminUserLabel(id: string): Promise<boolean> {
|
|
const ok = await rpcOrValue('rpc_admin_user_label_delete', {
|
|
p_id: id
|
|
} as any)
|
|
return ok === true
|
|
}
|
|
|
|
export async function setAdminUserLabelStatus(id: string, status: number): Promise<boolean> {
|
|
const ok = await rpcOrValue('rpc_admin_user_label_set_status', {
|
|
p_id: id,
|
|
p_status: status
|
|
} as any)
|
|
return ok === true
|
|
}
|