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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchList(
|
async function fetchList<
|
||||||
opts?: {
|
Options extends {
|
||||||
page?: number;
|
page?: number;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
query?: string;
|
query?: string;
|
||||||
|
includeBranch?: boolean;
|
||||||
},
|
},
|
||||||
|
Data extends Pagination<
|
||||||
|
(Customer &
|
||||||
|
(Options['includeBranch'] extends true
|
||||||
|
? { branch: CustomerBranch[] }
|
||||||
|
: unknown))[]
|
||||||
|
>,
|
||||||
|
>(
|
||||||
|
opts?: Options,
|
||||||
flow?: {
|
flow?: {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
refTransactionId: string;
|
refTransactionId: string;
|
||||||
transactionId: string;
|
transactionId: string;
|
||||||
},
|
},
|
||||||
) {
|
): Promise<Data | false> {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (opts?.pageSize && opts?.pageSize > 0) {
|
for (const [k, v] of Object.entries(opts || {})) {
|
||||||
params.append('pageSize', `${opts.pageSize}`);
|
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 query = params.toString();
|
||||||
|
|
||||||
const res = await api.get<Pagination<Customer[]>>(
|
const res = await api.get<Data>(
|
||||||
`/customer${(params && '?'.concat(query)) || ''}`,
|
`/customer${(params && '?'.concat(query)) || ''}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -75,10 +82,11 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res && res.status === 200) {
|
if (!res) return false;
|
||||||
data.value = res.data;
|
if (res.status === 200) {
|
||||||
return data.value;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue