-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchData.ts
30 lines (26 loc) · 918 Bytes
/
fetchData.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {
userSchema, userType,
cartSchema, cartType,
productsSchema, productType
} from "./response.interface";
import axios from "axios";
import { z } from "zod";
const getUsers = async (): Promise<userType[]> => {
const response = await axios("https://fakestoreapi.com/users");
return z.array(userSchema).parse(response.data);
}
const getCarts = async (): Promise<cartType[]> => {
const response = await axios("https://fakestoreapi.com/carts/?startdate=2000-01-01&enddate=2023-04-07");
return z.array(cartSchema).parse(response.data);
}
const getProducts = async (): Promise<productType[]> => {
const response = await axios("http://fakestoreapi.com/products");
return z.array(productsSchema).parse(response.data);
}
export const getData = async () => {
return await Promise.all([
getUsers(),
getCarts(),
getProducts(),
]);
}