Download TravelYaari-react/src/admin/apiAdmin.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.64 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/admin/apiAdmin.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/admin/apiAdmin.js
-
curl -L -o apiAdmin.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/admin/apiAdmin.js
4.64 kB
| import { API } from '../config'; | |
| export const createCategory = (userId, token, category) => { | |
| return fetch(`${API}/category/create/${userId}`, { | |
| method: 'POST', | |
| headers: { | |
| Accept: 'application/json', | |
| 'Content-Type': 'application/json', | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: JSON.stringify(category) | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => { | |
| console.log(err); | |
| }); | |
| }; | |
| export const updateCategory = (categoryId, userId, token, category) => { | |
| return fetch(`${API}/category/${categoryId}/${userId}`, { | |
| method: 'PUT', | |
| headers: { | |
| // content type? | |
| 'Content-Type': 'application/json', | |
| Accept: 'application/json', | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: JSON.stringify(category) | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const createProduct = (userId, token, product) => { | |
| return fetch(`${API}/product/create/${userId}`, { | |
| method: 'POST', | |
| headers: { | |
| Accept: 'application/json', | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: product | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => { | |
| console.log(err); | |
| }); | |
| }; | |
| export const getCategory = categoryId => { | |
| return fetch(`${API}/category/${categoryId}`, { | |
| method: 'GET' | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const getCategories = () => { | |
| return fetch(`${API}/categories`, { | |
| method: 'GET' | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const listOrders = (userId, token) => { | |
| return fetch(`${API}/order/list/${userId}`, { | |
| method: 'GET', | |
| headers: { | |
| Accept: 'application/json', | |
| Authorization: `Bearer ${token}` | |
| } | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const getStatusValues = (userId, token) => { | |
| return fetch(`${API}/order/status-values/${userId}`, { | |
| method: 'GET', | |
| headers: { | |
| Accept: 'application/json', | |
| Authorization: `Bearer ${token}` | |
| } | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const updateOrderStatus = (userId, token, orderId, status) => { | |
| return fetch(`${API}/order/${orderId}/status/${userId}`, { | |
| method: 'PUT', | |
| headers: { | |
| Accept: 'application/json', | |
| 'Content-Type': 'application/json', | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: JSON.stringify({ status, orderId }) | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| /** | |
| * to perform crud on product | |
| * get all products | |
| * get a single product | |
| * update single product | |
| * delete single product | |
| */ | |
| export const getProducts = () => { | |
| return fetch(`${API}/products?limit=undefined`, { | |
| method: 'GET' | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const deleteProduct = (productId, userId, token) => { | |
| return fetch(`${API}/product/${productId}/${userId}`, { | |
| method: 'DELETE', | |
| headers: { | |
| Accept: 'application/json', | |
| 'Content-Type': 'application/json', | |
| Authorization: `Bearer ${token}` | |
| } | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const getProduct = productId => { | |
| return fetch(`${API}/product/${productId}`, { | |
| method: 'GET' | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const updateProduct = (productId, userId, token, product) => { | |
| return fetch(`${API}/product/${productId}/${userId}`, { | |
| method: 'PUT', | |
| headers: { | |
| Accept: 'application/json', | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: product | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |