md с api, подправил запросы
This commit is contained in:
1 parent
cee1ed8bb7
commit
5451970f02
3 files changed
+157
-9
No files matched your search
@@ -5,7 +5,7 @@ import axios from "axios";
|
||||
export const fetchCategories = createAsyncThunk<Category[]>(
|
||||
"categories/fetchCategories",
|
||||
async () => {
|
||||
const res = await axios.get("/api/categories");
|
||||
const res = await axios.get<Category[]>("/api/categories");
|
||||
return res.data;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -11,6 +11,13 @@ interface FetchParams {
|
||||
filters?: Record<string, string | number | (string | number)[]>;
|
||||
}
|
||||
|
||||
interface FetchResponce{
|
||||
items: Product[],
|
||||
total: number,
|
||||
page: number,
|
||||
limit: number,
|
||||
}
|
||||
|
||||
export const fetchProductsByCategory = createAsyncThunk(
|
||||
"products/fetchByCategory",
|
||||
async (params: FetchParams) => {
|
||||
@@ -26,7 +33,7 @@ export const fetchProductsByCategory = createAsyncThunk(
|
||||
else qp.append(k, String(v));
|
||||
});
|
||||
}
|
||||
const res = await client.get(`/products?${qp.toString()}`);
|
||||
const res = await client.get<FetchResponce>(`/products?${qp.toString()}`);
|
||||
// ожидаем { items: Product[], total: number, page: number, limit: number }
|
||||
return res.data;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user