✨ Changes to backend in utils
This commit is contained in:
parent
35e078f2ff
commit
b5c6b47574
4 changed files with 31 additions and 23 deletions
|
@ -23,6 +23,7 @@ packageJson:
|
||||||
- "Ogol/*"
|
- "Ogol/*"
|
||||||
- "Robot/*"
|
- "Robot/*"
|
||||||
- "SampleConfigurator/*"
|
- "SampleConfigurator/*"
|
||||||
|
- "Spinner/*"
|
||||||
- "withGist/*"
|
- "withGist/*"
|
||||||
- "withLanguage/*"
|
- "withLanguage/*"
|
||||||
- "withStorage/*"
|
- "withStorage/*"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* @freesewing/components/Spinner | v2.0.0-beta.19
|
* @freesewing/components/Spinner | v2.0.0-beta.19-1
|
||||||
* A collection of React components for FreeSewing web UIs
|
* A collection of React components for FreeSewing web UIs
|
||||||
* (c) 2019 Joost De Cock <joost@decock.org> (https://github.com/joostdecock)
|
* (c) 2019 Joost De Cock <joost@decock.org> (https://github.com/joostdecock)
|
||||||
* @license MIT
|
* @license MIT
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@freesewing/components",
|
"name": "@freesewing/components",
|
||||||
"version": "2.0.0-beta.19",
|
"version": "2.0.0-beta.19-1",
|
||||||
"description": "A collection of React components for FreeSewing web UIs",
|
"description": "A collection of React components for FreeSewing web UIs",
|
||||||
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
|
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
|
||||||
"homepage": "https://freesewing.org/",
|
"homepage": "https://freesewing.org/",
|
||||||
|
@ -59,6 +59,7 @@
|
||||||
"Ogol/*",
|
"Ogol/*",
|
||||||
"Robot/*",
|
"Robot/*",
|
||||||
"SampleConfigurator/*",
|
"SampleConfigurator/*",
|
||||||
|
"Spinner/*",
|
||||||
"withGist/*",
|
"withGist/*",
|
||||||
"withLanguage/*",
|
"withLanguage/*",
|
||||||
"withStorage/*",
|
"withStorage/*",
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import storage from "./storage";
|
|
||||||
|
|
||||||
function useBackend(baseURL, timeout = 10000) {
|
function useBackend(baseURL, timeout = 10000) {
|
||||||
// Configure Axios
|
// Configure Axios
|
||||||
const api = axios.create({ baseURL, timeout });
|
const api = axios.create({ baseURL, timeout });
|
||||||
|
|
||||||
// Helper method for Authorization header
|
// Helper method for Authorization header
|
||||||
const auth = (token = storage.get("token")) => ({
|
const auth = token => ({
|
||||||
headers: { Authorization: "Bearer " + token }
|
headers: { Authorization: "Bearer " + token }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -30,29 +29,36 @@ function useBackend(baseURL, timeout = 10000) {
|
||||||
backend.loadPatrons = handle => api.get("/patrons"); // Load patron list
|
backend.loadPatrons = handle => api.get("/patrons"); // Load patron list
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
backend.account = () => api.get("/account", auth()); // Try to authenticate based on stored token
|
backend.account = token => api.get("/account", auth(token)); // Try to authenticate based on stored token
|
||||||
backend.export = () => api.get("/export", auth()); // Export data
|
backend.export = token => api.get("/export", auth(token)); // Export data
|
||||||
backend.restrict = () => api.get("/restrict", auth()); // Restrict data processing (freeze account)
|
backend.restrict = token => api.get("/restrict", auth(token)); // Restrict data processing (freeze account)
|
||||||
backend.remove = () => api.get("/remove", auth()); // Remove account
|
backend.remove = token => api.get("/remove", auth(token)); // Remove account
|
||||||
backend.saveAccount = data => api.put("/user", data, auth()); // Update account
|
backend.saveAccount = (data, token) => {
|
||||||
backend.availableUsername = data =>
|
console.log("in utils, token is", token);
|
||||||
api.post("/available/username", data, auth()); // Check is a username is available
|
return api.put("/user", data, auth(token)); // Update account
|
||||||
backend.resetPassword = username =>
|
};
|
||||||
api.post("/reset/password", { username: username }, auth()); // Ask for a password reset
|
backend.availableUsername = (data, token) =>
|
||||||
backend.setPassword = data => api.post("/set/password", data, auth()); // (re)set a new password
|
api.post("/available/username", data, auth(token)); // Check is a username is available
|
||||||
|
backend.resetPassword = (username, token) =>
|
||||||
|
api.post("/reset/password", { username: username }, auth(token)); // Ask for a password reset
|
||||||
|
backend.setPassword = (data, token) =>
|
||||||
|
api.post("/set/password", data, auth(token)); // (re)set a new password
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
backend.removeModels = data => api.post("/remove/models", data, auth()); // Delete multiple models
|
backend.removeModels = (data, token) =>
|
||||||
backend.createModel = data => api.post("/model", data, auth()); // Create model
|
api.post("/remove/models", data, auth(token)); // Delete multiple models
|
||||||
backend.saveModel = (handle, data) =>
|
backend.createModel = (data, token) => api.post("/model", data, auth(token)); // Create model
|
||||||
api.put("/model/" + handle, data, auth()); // Update model
|
backend.saveModel = (handle, data, token) =>
|
||||||
|
api.put("/model/" + handle, data, auth(token)); // Update model
|
||||||
|
|
||||||
// Drafts
|
// Drafts
|
||||||
backend.createDraft = data => api.post("/draft", data, auth()); // Create draft
|
backend.createDraft = (data, token) => api.post("/draft", data, auth(token)); // Create draft
|
||||||
backend.saveDraft = (handle, data) =>
|
backend.saveDraft = (handle, data, token) =>
|
||||||
api.put("/draft/" + handle, data, auth()); // Update draft
|
api.put("/draft/" + handle, data, auth(token)); // Update draft
|
||||||
backend.removeDraft = handle => api.delete("/draft/" + handle, auth()); // Remove draft
|
backend.removeDraft = (handle, token) =>
|
||||||
backend.removeDrafts = data => api.post("/remove/drafts", data, auth()); // Delete multiple drafts
|
api.delete("/draft/" + handle, auth(token)); // Remove draft
|
||||||
|
backend.removeDrafts = (data, token) =>
|
||||||
|
api.post("/remove/drafts", data, auth(token)); // Delete multiple drafts
|
||||||
|
|
||||||
return backend;
|
return backend;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue