87 行
2.3 KiB
TypeScript
87 行
2.3 KiB
TypeScript
import { apiRequestData } from "./http";
|
|
|
|
export type ReimbursementTemplateItem = {
|
|
expenseTypeId: string;
|
|
description: string;
|
|
defaultAmount?: string;
|
|
};
|
|
|
|
export type ReimbursementTemplate = {
|
|
id: string;
|
|
name: string;
|
|
description: string | null;
|
|
items: ReimbursementTemplateItem[];
|
|
sortOrder: number;
|
|
enabled: boolean;
|
|
createdAt: string | null;
|
|
updatedAt: string | null;
|
|
};
|
|
|
|
export type ReimbursementTemplateListResponse = {
|
|
enabled: boolean | null;
|
|
items: ReimbursementTemplate[];
|
|
};
|
|
|
|
export type ReimbursementTemplateListQuery = {
|
|
enabled?: boolean;
|
|
};
|
|
|
|
export type CreateReimbursementTemplatePayload = {
|
|
name: string;
|
|
description?: string | null;
|
|
items?: ReimbursementTemplateItem[];
|
|
sortOrder?: number;
|
|
enabled?: boolean;
|
|
};
|
|
|
|
export type UpdateReimbursementTemplatePayload = {
|
|
name?: string;
|
|
description?: string | null;
|
|
items?: ReimbursementTemplateItem[];
|
|
sortOrder?: number;
|
|
enabled?: boolean;
|
|
};
|
|
|
|
function toQueryString(query: Record<string, string | number | boolean | undefined>) {
|
|
const params = new URLSearchParams();
|
|
|
|
for (const [key, value] of Object.entries(query)) {
|
|
if (value == null || value === "") {
|
|
continue;
|
|
}
|
|
params.set(key, String(value));
|
|
}
|
|
|
|
const encoded = params.toString();
|
|
return encoded ? `?${encoded}` : "";
|
|
}
|
|
|
|
export async function fetchReimbursementTemplates(query: ReimbursementTemplateListQuery = {}) {
|
|
return apiRequestData<ReimbursementTemplateListResponse>(
|
|
`/api/reimbursement-templates${toQueryString(query as Record<string, string | number | boolean | undefined>)}`,
|
|
);
|
|
}
|
|
|
|
export async function createReimbursementTemplate(payload: CreateReimbursementTemplatePayload) {
|
|
return apiRequestData<ReimbursementTemplate>("/api/reimbursement-templates", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function updateReimbursementTemplate(
|
|
templateId: string,
|
|
payload: UpdateReimbursementTemplatePayload,
|
|
) {
|
|
return apiRequestData<ReimbursementTemplate>(`/api/reimbursement-templates/${templateId}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function deleteReimbursementTemplate(templateId: string) {
|
|
return apiRequestData<ReimbursementTemplate>(`/api/reimbursement-templates/${templateId}`, {
|
|
method: "DELETE",
|
|
});
|
|
}
|