80 lines
2.1 KiB
JavaScript
Raw Normal View History

async function fetch_history() {
try {
const response = await fetch(`${currentUrl}app/datahistory`);
const rawData = await response.json();
var dateFormat = d3.timeParse("%a, %d %b %Y %H:%M:%S GMT");
// SELECT uuid, quantity, discount_percentage, price, currency, h_timestamp
let historyData = rawData.map(d => ({
uuid: d[0],
value: parseFloat(d[3].replace('$', '')),
currency: d[4],
date: dateFormat(d[5]),
}));
return historyData;
} catch (error) {
console.error('Error fetching data history: ', error);
throw error;
}
}
async function fetch_item() {
try {
2024-02-05 09:30:29 +01:00
// SELECT uuid, itemid, skuid, choice, attributes, image, show
const response = await fetch(`${currentUrl}app/dataitem`);
const rawData = await response.json();
const items = rawData.reduce((item, row) => {
const uuid = row[0];
const itemid = row[1];
const skuid = row[2];
const choice = row[3];
const attributes = row[4];
const image = row[5];
2024-02-05 09:30:29 +01:00
const show = row[6];
const values = {
itemid: itemid,
skuid: skuid,
choice: choice,
attributes: attributes,
image: image,
2024-02-05 09:30:29 +01:00
show: show,
};
item[uuid] = values;
return item;
}, {});
return items;
} catch (error) {
console.error('Error fetching data item: ', error);
throw error;
}
}
async function get_data() {
items_data = await fetch_item();
history_data = await fetch_history();
// console.log(items_data)
// console.log(history_data)
return Array(items_data, history_data);
}
async function fetch_list() {
try {
const response = await fetch(`${currentUrl}app/datalist`);
const rawData = await response.json();
// SELECT uuid, name, description
let listData = rawData.map(d => ({
uuid: d[0],
name: d[1],
description: d[2],
}));
return listData;
} catch (error) {
console.error('Error fetching data history: ', error);
throw error;
}
}