-
-
Save leochiu-a/4a2c9e5dadb56fa26efb454ecb3cee4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment