feat: เพิ่ม fetchListBranch
This commit is contained in:
parent
17ca97165b
commit
fd0cde4f42
1 changed files with 53 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import {
|
||||||
CustomerStats,
|
CustomerStats,
|
||||||
CustomerBranch,
|
CustomerBranch,
|
||||||
CustomerBranchCreate,
|
CustomerBranchCreate,
|
||||||
|
CustomerType,
|
||||||
} from './types';
|
} from './types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
@ -43,12 +44,63 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchListBranch<
|
||||||
|
Options extends {
|
||||||
|
zipCode?: string;
|
||||||
|
customerId?: string;
|
||||||
|
includeCustomer?: boolean;
|
||||||
|
query?: string;
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
},
|
||||||
|
Data extends Pagination<
|
||||||
|
(CustomerBranch &
|
||||||
|
(Options['includeCustomer'] extends true
|
||||||
|
? { customer: Customer }
|
||||||
|
: unknown))[]
|
||||||
|
>,
|
||||||
|
>(
|
||||||
|
opts?: Options,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
): Promise<Data | false> {
|
||||||
|
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<Data>(
|
||||||
|
`/customer-branch${(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 fetchList<
|
async function fetchList<
|
||||||
Options extends {
|
Options extends {
|
||||||
page?: number;
|
page?: number;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
query?: string;
|
query?: string;
|
||||||
includeBranch?: boolean;
|
includeBranch?: boolean;
|
||||||
|
customerType?: CustomerType;
|
||||||
},
|
},
|
||||||
Data extends Pagination<
|
Data extends Pagination<
|
||||||
(Customer &
|
(Customer &
|
||||||
|
|
@ -373,6 +425,7 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
|
|
||||||
getStatsCustomer,
|
getStatsCustomer,
|
||||||
|
|
||||||
|
fetchListBranch,
|
||||||
fetchListById,
|
fetchListById,
|
||||||
fetchList,
|
fetchList,
|
||||||
create,
|
create,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue