fix: แก้ type ของ fetchList

This commit is contained in:
Net 2024-06-07 18:04:52 +07:00
parent 713b872fd9
commit b49b6792d5

View file

@ -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;
} }