51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
/**
|
|
* features/auth/api/user.api.ts
|
|
* 用户域 HTTP API:资料、请假、密码重置、Agent 列表等。
|
|
*/
|
|
import { getAuthHeaders } from '@/utils/auth';
|
|
import { requestJson } from '@/shared/api/client';
|
|
|
|
const auth = () => ({ headers: getAuthHeaders() });
|
|
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
|
|
|
export const getUserProfile = () => requestJson<Record<string, any>>('/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<LeaveBalanceResult>(`/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<string, any>) =>
|
|
requestJson<LeaveWorkflowSubmitResult>('/api/user/leave-workflow/submit', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(form),
|
|
});
|
|
|
|
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<Record<string, any>>(`/api/user/agents/${agentId}`, auth());
|
|
|
|
export const listUserAgents = () => requestJson<any[]>('/api/agents', auth());
|
|
|
|
export const listAgentGuides = (agentId: number) => requestJson<any[]>(`/api/agents/${agentId}/guides`, auth());
|