-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake-data.ts
61 lines (56 loc) · 2.11 KB
/
fake-data.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
export interface Product {
id: string;
title: string;
price: number;
description: string;
category: string;
image: string;
}
// https://fakestoreapi.com/
const FAKE_PRODUCT_DATA: Product[] = [
{
id: "1",
title: "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
price: 109.95,
description:
"Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
category: "men's clothing",
image: "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
},
{
id: "2",
title: "Mens Casual Premium Slim Fit T-Shirts ",
price: 22.3,
description:
"Slim-fitting style, contrast raglan long sleeve, three-button henley placket, light weight & soft fabric for breathable and comfortable wearing. And Solid stitched shirts with round neck made for durability and a great fit for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-button placket.",
category: "men's clothing",
image:
"https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_.jpg",
},
{
id: "3",
title: "Mens Cotton Jacket",
price: 55.99,
description:
"great outerwear jackets for Spring/Autumn/Winter, suitable for many occasions, such as working, hiking, camping, mountain/rock climbing, cycling, traveling or other outdoors. Good gift choice for you or your family member. A warm hearted love to Father, husband or son in this thanksgiving or Christmas Day.",
category: "men's clothing",
image: "https://fakestoreapi.com/img/71li-ujtlUL._AC_UX679_.jpg",
},
];
export type Direction = "ASC" | "DES";
export function getAllProduct() {
return FAKE_PRODUCT_DATA;
}
export function sortByPrice(direction: Direction) {
return FAKE_PRODUCT_DATA.sort((a, b) => {
if (direction === "ASC") {
return a.price - b.price;
} else {
return b.price - a.price;
}
});
}
export function getProductById(id: string) {
const product = FAKE_PRODUCT_DATA.find((product) => product.id === id);
return product || FAKE_PRODUCT_DATA[0];
}