...
 
Commits (2)
const Std = require("../Std");
class APIHandler {
static async call(path, type, obj = {}) {
return new Promise((res, rej) => {
const requestType = ["GET", "PUT", "POST", "DELETE"];
let options = {
method : requestType[type],
mode : "cors",
cache : "no-cache",
headers : {
"Content-Type" : "application/json"
},
redirect : "follow",
referrer : "no-referrer"
};
if (type === APIHandler.REQUESTTYPE.POST || type === APIHandler.REQUESTTYPE.PUT) options.body = obj;
fetch(path, options).then(response => {
if (response.status !== 200) {
if (response.status !== 404) {
alert("Problem: " + response.statusText);
//TODO: Add Modal, change Alert to Modal
return rej(response.statusText)
}
return res({"data" : {}, "statusCode" : response.status});
}
return res(response.json())
}).catch(err => {
return rej("API network problem - " + err);
});
});
}
}
APIHandler.REQUESTTYPE = {
"GET" : 0,
"PUT" : 1,
"POST" : 2,
"DELETE" : 3
};
module.exports = APIHandler;
\ No newline at end of file
......@@ -6,6 +6,9 @@
* Copyright: Philipp Dippel
*/
const APIHandler = require("../../backend/APIHandler");
const Std = require("../../Std");
class Controls {
constructor() {
......@@ -42,9 +45,16 @@ class Controls {
break;
}
}
getProductInfo() {
console.log("Produktinfos")
//Todo Change Dummy API Request
async getProductInfo() {
console.log("Produktinfos");
try {
let products = await APIHandler.call("http://127.0.0.1:9080/api/produc", APIHandler.REQUESTTYPE.GET);
console.log(products);
}
catch (err) {
Std.Log("Error: " + err, Std.LogLevel.ERROR);
}
}
cashier() {
......