Re-working the API library functions and files

This commit is contained in:
Scott Idem
2024-05-23 18:20:31 -04:00
parent fa58d1accb
commit 42fef3feb8
17 changed files with 1797 additions and 92 deletions

View File

@@ -0,0 +1,60 @@
import axios from 'axios';
// Updated 2024-05-23
export let patch_object = async function patch_object(
{
api_cfg=null,
endpoint='',
params={},
data={},
return_meta=false,
log_lvl=0
} : {
api_cfg: any,
endpoint: string,
params?: any,
data?: any,
return_meta?: boolean,
log_lvl?: number
}
) {
console.log('*** patch_object() ***');
if (log_lvl) {
// console.log(api_cfg);
console.log(endpoint);
console.log(params);
if (log_lvl > 1) {
console.log(data);
}
// console.log(return_meta);
// console.log(as_list);
}
let axios_api = axios.create({
baseURL: api_cfg['base_url'],
/* other custom settings */
});
axios_api.defaults.headers = api_cfg['headers'];
let response_data = await axios_api.patch(endpoint, data, { params: params })
.then(function (response) {
console.log(response.data);
return response.data['data'];
//return response.data;
})
.catch(function (error) {
if (error.response && error.response.status === 404) {
return null; // Returning null since there were no results
}
console.log(error);
return false; // Returning false since something may have gone wrong. Also more in line with what the API returns.
// return error;
});
if (log_lvl > 1) {
console.log(response_data);
}
return response_data;
}