/** * features/auth/api/user.api.ts * 用户域 HTTP API:资料、请假、密码重置、Agent 列表等。 */ import { getAuthHeaders } from '@/shared/utils/auth'; import { requestJson } from '@/shared/api/client'; const auth = () => ({ headers: getAuthHeaders() }); const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } }); export const getUserProfile = () => requestJson>('/api/user/profile', auth()); export interface LeaveBalanceResult { has_balance: boolean; leave_type_label: string; year: number; total_hours: number | null; used_hours: number | null; remaining_hours: number | null; } export const getLeaveBalance = (leaveType: string) => requestJson(`/api/user/leave-balance?leave_type=${encodeURIComponent(leaveType)}`, auth()); export interface LeaveWorkflowSubmitResult { request_id?: string; submitted_at?: string; request_name?: string; } export const submitLeaveWorkflow = (form: Record) => requestJson('/api/user/leave-workflow/submit', { method: 'POST', ...jsonAuth(), body: JSON.stringify(form), }); export const resetPasswordByWecom = (employeeId: string, username: string) => requestJson('/api/user/reset-password-by-wecom', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ employee_id: employeeId, username }), }); export const resetPasswordConfirm = (token: string, newPassword: string) => requestJson('/api/user/reset-password-confirm', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, new_password: newPassword }), }); export const getUserAgent = (agentId: number) => requestJson>(`/api/user/agents/${agentId}`, auth()); export const listUserAgents = () => requestJson('/api/agents', auth()); export const listAgentGuides = (agentId: number) => requestJson(`/api/agents/${agentId}/guides`, auth());