This commit is contained in:
2020-09-08 19:10:56 +00:00
parent 10abb41a0c
commit 1ac6fc68a7
2 changed files with 71 additions and 26 deletions

View File

@@ -34,15 +34,65 @@ async function ayPreRender(ayAllData) {
}
}
// function ayPreRender(ayAllData) {
// if (typeof ayPrepareData === "function") {
// return ayPrepareData(ayAllData);
// } else {
// return ayAllData;
// }
// }
///////////////////////////////////
// GET DATA FROM API SERVER
//
async function ayGetFromAPI(route, token) {
try {
let r = await fetch(route, {
method: "get",
mode: "cors",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: token
}
});
return await r.json();
} catch (error) {
//fundamental error, can't proceed with this call
// handleError("GET", error, route);
//todo: deal with this properly
throw error;
}
}
// function ayPreRender(ayAllData) {
// return ayAllData;
// // return typeof ayPrepareData;
// }
///////////////////////////////////
// POST DATA TO API SERVER
//
async function ayPostToAPI(route, token, data) {
try {
fetchOptions = {
method: "post",
mode: "cors",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: token
},
body: JSON.stringify(data)
};
let r = await fetch(route, fetchOptions);
return await r.json();
} catch (error) {
//todo: better handle this
throw error;
}
}
/*
async function ayPrepareData(reportData) {
//this function (if present) is called with the report data
//before the report is rendered
//modify data as required here and return it to change the data before the report renders
//Example of using API method to fetch data from API server and make it available to the report template
let route=`${reportData.ayServerMetaData.ayApiUrl}enum-list/list/AyaType`;
//Put the data into the main report data object so it's available to the template
reportData.myData={AyaTypeList:await ayGetFromAPI(route, reportData.ayClientMetaData.Authorization)};
return reportData;
}
*/