feat: add api function invoice
This commit is contained in:
parent
b1904a4d99
commit
78b68eb57f
2 changed files with 93 additions and 0 deletions
68
src/stores/invoice/index.ts
Normal file
68
src/stores/invoice/index.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { PaginationResult } from 'src/types';
|
||||
import { Invoice, InvoicePayload } from './types';
|
||||
|
||||
export const useWorkflowTemplate = defineStore('workflow-store', () => {
|
||||
const data = ref<Invoice[]>([]);
|
||||
const page = ref<number>(1);
|
||||
const pageMax = ref<number>(1);
|
||||
const pageSize = ref<number>(30);
|
||||
|
||||
async function getInvoice(id: string) {
|
||||
const res = await api.get<Invoice>(`/invoice/${id}`);
|
||||
|
||||
if (res.status >= 400) return null;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function getInvoiceList(params?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
query?: string;
|
||||
}) {
|
||||
const res = await api.get<PaginationResult<Invoice>>('/workflow-template', {
|
||||
params,
|
||||
});
|
||||
|
||||
if (res.status >= 400) return null;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function creatInvoice(data: InvoicePayload) {
|
||||
const res = await api.post<Invoice>('/invoice', data);
|
||||
if (res.status >= 400) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
async function editInvoice(data: InvoicePayload & { id: string }) {
|
||||
const res = await api.put<Invoice>(`/invoice/${data.id}`, {
|
||||
...data,
|
||||
id: undefined,
|
||||
});
|
||||
if (res.status >= 400) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
async function deleteInvoice(id: string) {
|
||||
const res = await api.delete<Invoice>(`/invoice/${id}`);
|
||||
if (res.status >= 400) return null;
|
||||
return res;
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
page,
|
||||
pageSize,
|
||||
pageMax,
|
||||
|
||||
getInvoice,
|
||||
getInvoiceList,
|
||||
creatInvoice,
|
||||
editInvoice,
|
||||
deleteInvoice,
|
||||
};
|
||||
});
|
||||
25
src/stores/invoice/types.ts
Normal file
25
src/stores/invoice/types.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { Quotation, QuotationFull } from '../quotations/types';
|
||||
import { CreatedBy } from '../types';
|
||||
|
||||
export type Invoice = {
|
||||
id: string;
|
||||
|
||||
amount: number;
|
||||
|
||||
productServiceList: QuotationFull['productServiceList'];
|
||||
|
||||
quotation: Quotation;
|
||||
|
||||
createdAt: string;
|
||||
createdBy: CreatedBy;
|
||||
createdByUserId: string;
|
||||
};
|
||||
|
||||
export type InvoicePayload = {
|
||||
quotationId: string;
|
||||
amount: number;
|
||||
// NOTE: For individual list that will be include in the quotation
|
||||
productServiceListId?: string[];
|
||||
// NOTE: Will be pulled from quotation
|
||||
installmentNo?: number[];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue