fix: แก้ type ของ fetchList
This commit is contained in:
parent
713b872fd9
commit
b49b6792d5
1 changed files with 19 additions and 11 deletions
|
|
@ -42,29 +42,36 @@ const useCustomerStore = defineStore('api-customer', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function fetchList(
|
||||
opts?: {
|
||||
async function fetchList<
|
||||
Options extends {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
query?: string;
|
||||
includeBranch?: boolean;
|
||||
},
|
||||
Data extends Pagination<
|
||||
(Customer &
|
||||
(Options['includeBranch'] extends true
|
||||
? { branch: CustomerBranch[] }
|
||||
: unknown))[]
|
||||
>,
|
||||
>(
|
||||
opts?: Options,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
): Promise<Data | false> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (opts?.pageSize && opts?.pageSize > 0) {
|
||||
params.append('pageSize', `${opts.pageSize}`);
|
||||
for (const [k, v] of Object.entries(opts || {})) {
|
||||
v !== undefined && params.append(k, v.toString());
|
||||
}
|
||||
if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`);
|
||||
if (opts?.query) params.append('query', opts.query);
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<Pagination<Customer[]>>(
|
||||
const res = await api.get<Data>(
|
||||
`/customer${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
|
|
@ -75,10 +82,11 @@ const useCustomerStore = defineStore('api-customer', () => {
|
|||
},
|
||||
);
|
||||
|
||||
if (res && res.status === 200) {
|
||||
data.value = res.data;
|
||||
return data.value;
|
||||
if (!res) return false;
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue