- 报销创建支持选择 ownerEmployeeId(delegation-grants received) - 票据上传支持 owner_employee_id(delegation-grants received) - 保持普通员工流程不变,权限不足由后端阻断
75 行
1.9 KiB
TypeScript
75 行
1.9 KiB
TypeScript
import { apiRequestData } from "./http";
|
|
|
|
export type DelegationStatus = "active" | "scheduled" | "expired" | "revoked";
|
|
|
|
export type DelegationItem = {
|
|
id: string;
|
|
principalEmployeeId: string;
|
|
delegateEmployeeId: string;
|
|
scope: "reimbursement_submit" | "all";
|
|
validFrom: string;
|
|
validTo: string | null;
|
|
revokedAt: string | null;
|
|
createdAt: string;
|
|
status: DelegationStatus;
|
|
principal?: {
|
|
id: string;
|
|
employeeNo: string;
|
|
name: string;
|
|
departmentId: string;
|
|
status: string;
|
|
roleCodes: string[];
|
|
} | null;
|
|
delegate?: {
|
|
id: string;
|
|
employeeNo: string;
|
|
name: string;
|
|
departmentId: string;
|
|
status: string;
|
|
roleCodes: string[];
|
|
} | null;
|
|
};
|
|
|
|
export type CreateDelegationRequest = {
|
|
delegateEmployeeId: string;
|
|
scope?: "reimbursement_submit" | "all";
|
|
validFrom?: string;
|
|
validTo?: string;
|
|
};
|
|
|
|
export type CreateDelegationResponse = {
|
|
delegation: DelegationItem;
|
|
};
|
|
|
|
export type FetchMyDelegationsResponse = {
|
|
status: "active" | "scheduled" | "expired" | "revoked" | "all";
|
|
initiated: DelegationItem[];
|
|
received: DelegationItem[];
|
|
};
|
|
|
|
export async function createDelegation(payload: CreateDelegationRequest) {
|
|
return apiRequestData<CreateDelegationResponse>("/api/delegations", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function fetchMyDelegations(status: FetchMyDelegationsResponse["status"] = "active") {
|
|
const params = new URLSearchParams();
|
|
if (status && status !== "active") {
|
|
params.set("status", status);
|
|
}
|
|
const query = params.toString();
|
|
return apiRequestData<FetchMyDelegationsResponse>(`/api/delegations/mine${query ? `?${query}` : ""}`);
|
|
}
|
|
|
|
export async function revokeDelegation(delegationId: string) {
|
|
return apiRequestData<{ delegation: DelegationItem; outcome: string }>(
|
|
`/api/delegations/${delegationId}/revoke`,
|
|
{
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
}
|