Complete system for getting + saving Product Categories with new database, server, and client architecture.

This commit is contained in:
2024-09-01 21:57:46 +01:00
parent ba50aec9c9
commit b3e801e1ec
303 changed files with 4358 additions and 2885 deletions

View File

@@ -9,7 +9,7 @@ export default class API {
}
static async request(hashEndpoint, method = 'GET', data = null) {
const url = mapHashToController(hashEndpoint);
const url = API.getUrlFromHash(hashEndpoint);
const options = {
method,
headers: {
@@ -18,10 +18,12 @@ export default class API {
}
};
if (data) { //} && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
options.body = JSON.stringify(data);
}
console.log('API request:', method, url, data);
try {
const response = await fetch(url, options);
if (!response.ok) {
@@ -33,6 +35,13 @@ export default class API {
throw error;
}
}
static getUrlFromHash(hash) {
if (hash == null) hash = hashPageHome;
console.log("getUrlFromHash:");
console.log("base url: " + _pathHost + "\nhash: " + hash);
return _pathHost + hash;
}
// specific api calls
@@ -48,6 +57,24 @@ export default class API {
callback[keyCallback] = DOM.getHashPageCurrent();
return await API.request(hashPageUserLogin, 'POST', callback);
}
// store
// categories
static async getCategories() {
return await API.request(hashGetStoreProductCategory);
}
static async getCategoriesByFilters(formFilters) {
let dataRequest = {};
dataRequest[keyForm] = DOM.convertForm2JSON(formFilters);
return await API.request(hashGetStoreProductCategory, 'POST', dataRequest);
}
static async saveCategories(categories, formFilters, comment) {
let dataRequest = {};
dataRequest[keyForm] = DOM.convertForm2JSON(formFilters);
dataRequest[flagCategory] = categories;
dataRequest[flagComment] = comment;
return await API.request(hashSaveStoreProductCategory, 'POST', dataRequest);
}
}
/*