feat: เพิ่ม function ต่อ api Product Group
This commit is contained in:
parent
73afca7b57
commit
40aebe30a1
1 changed files with 108 additions and 1 deletions
|
|
@ -1,5 +1,112 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { ProductGroup, ProductGroupCreate, ProductGroupUpdate } from './types';
|
||||
|
||||
const useProductServiceStore = defineStore('api-product-service', () => {
|
||||
return {};
|
||||
async function fetchStatsProductGroup() {
|
||||
const res = await api.get('/product-group/stats');
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchListProductServiceById(groupId: string) {
|
||||
const res = await api.get<ProductGroup>(`/product-group/${groupId}`);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchListProductService(
|
||||
opts?: { query?: string },
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
for (const [k, v] of Object.entries(opts || {})) {
|
||||
v !== undefined && params.append(k, v.toString());
|
||||
}
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<ProductGroup>(
|
||||
`/product-group${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!res) return false;
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function createProductService() {
|
||||
const res = await api.post<ProductGroupCreate>('/product-group');
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function editProductService(
|
||||
groupId: string,
|
||||
opts: { data: ProductGroupUpdate },
|
||||
) {
|
||||
const res = await api.put<ProductGroupUpdate>(`/product-group/${groupId}`, {
|
||||
...opts.data,
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function deleteProductService(groupId: string) {
|
||||
const res = await api.delete(`/product-group/${groupId}`);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
fetchStatsProductGroup,
|
||||
fetchListProductServiceById,
|
||||
fetchListProductService,
|
||||
createProductService,
|
||||
editProductService,
|
||||
deleteProductService,
|
||||
};
|
||||
});
|
||||
|
||||
export default useProductServiceStore;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue