55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import axios from "@/config/axios";
|
|
import type {
|
|
CreatePreInvoiceType,
|
|
GetInvoiceResponseType,
|
|
InvoiceItemDetailType,
|
|
InvoiceType,
|
|
UpdatePreInvoiceType,
|
|
} from "../types/Types";
|
|
import type { InvoiceConfirmStatus } from "../enum/InvoiceEnum";
|
|
|
|
export type GetInvoicesParams = {
|
|
page?: number;
|
|
statuses?: InvoiceConfirmStatus[];
|
|
};
|
|
|
|
export const createInvoice = async (params: CreatePreInvoiceType) => {
|
|
const { data } = await axios.post("/admin/invoice", params);
|
|
return data;
|
|
};
|
|
|
|
export const getInvoice = async (
|
|
params: GetInvoicesParams = {},
|
|
): Promise<GetInvoiceResponseType> => {
|
|
const { page = 1, statuses } = params;
|
|
const { data } = await axios.get<GetInvoiceResponseType>("/admin/invoice", {
|
|
params: {
|
|
page,
|
|
...(statuses?.length ? { statuses: statuses.join(",") } : {}),
|
|
},
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const getInvoiceById = async (id: string) => {
|
|
const { data } = await axios.get<{ data: InvoiceType }>(`/admin/invoice/${id}`);
|
|
return data;
|
|
};
|
|
|
|
export const getInvoiceItemById = async (id: string) => {
|
|
const { data } = await axios.get<{ data: InvoiceItemDetailType }>(
|
|
`/admin/invoice/item/${id}`,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const updateInvoice = async (id: string, params: UpdatePreInvoiceType) => {
|
|
const { data } = await axios.patch(`/admin/invoice/${id}`, params);
|
|
return data;
|
|
};
|
|
|
|
export const archiveInvoice = async (id: string) => {
|
|
const { data } = await axios.patch(`/admin/invoice/${id}/archive`);
|
|
return data;
|
|
};
|