From 78b68eb57f257fffbba219b8e232db5a96ff730f Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 25 Oct 2024 16:54:32 +0700 Subject: [PATCH] feat: add api function invoice --- src/stores/invoice/index.ts | 68 +++++++++++++++++++++++++++++++++++++ src/stores/invoice/types.ts | 25 ++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/stores/invoice/index.ts create mode 100644 src/stores/invoice/types.ts diff --git a/src/stores/invoice/index.ts b/src/stores/invoice/index.ts new file mode 100644 index 00000000..9b41d7c9 --- /dev/null +++ b/src/stores/invoice/index.ts @@ -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([]); + const page = ref(1); + const pageMax = ref(1); + const pageSize = ref(30); + + async function getInvoice(id: string) { + const res = await api.get(`/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>('/workflow-template', { + params, + }); + + if (res.status >= 400) return null; + + return res.data; + } + + async function creatInvoice(data: InvoicePayload) { + const res = await api.post('/invoice', data); + if (res.status >= 400) return null; + return res; + } + + async function editInvoice(data: InvoicePayload & { id: string }) { + const res = await api.put(`/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/${id}`); + if (res.status >= 400) return null; + return res; + } + + return { + data, + page, + pageSize, + pageMax, + + getInvoice, + getInvoiceList, + creatInvoice, + editInvoice, + deleteInvoice, + }; +}); diff --git a/src/stores/invoice/types.ts b/src/stores/invoice/types.ts new file mode 100644 index 00000000..4c021f6c --- /dev/null +++ b/src/stores/invoice/types.ts @@ -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[]; +};