Download TravelYaari-react/src/user/apiUser.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/user/apiUser.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/user/apiUser.js
-
curl -L -o apiUser.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/TravelYaari-react/src/user/apiUser.js
1.62 kB
| import { API } from "../config"; | |
| export const read = (userId, token) => { | |
| return fetch(`${API}/user/${userId}`, { | |
| method: "GET", | |
| headers: { | |
| Accept: "application/json", | |
| "Content-Type": "application/json", | |
| Authorization: `Bearer ${token}` | |
| } | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const update = (userId, token, user) => { | |
| return fetch(`${API}/user/${userId}`, { | |
| method: "PUT", | |
| headers: { | |
| Accept: "application/json", | |
| "Content-Type": "application/json", | |
| Authorization: `Bearer ${token}` | |
| }, | |
| body: JSON.stringify(user) | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |
| export const updateUser = (user, next) => { | |
| if (typeof window !== "undefined") { | |
| if (localStorage.getItem("jwt")) { | |
| let auth = JSON.parse(localStorage.getItem("jwt")); | |
| auth.user = user; | |
| localStorage.setItem("jwt", JSON.stringify(auth)); | |
| next(); | |
| } | |
| } | |
| }; | |
| export const getPurchaseHistory = (userId, token) => { | |
| return fetch(`${API}/orders/by/user/${userId}`, { | |
| method: "GET", | |
| headers: { | |
| Accept: "application/json", | |
| "Content-Type": "application/json", | |
| Authorization: `Bearer ${token}` | |
| } | |
| }) | |
| .then(response => { | |
| return response.json(); | |
| }) | |
| .catch(err => console.log(err)); | |
| }; | |