summaryrefslogtreecommitdiff
path: root/src/core/utils/apiOdoo.js
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-03-01 09:18:52 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-03-01 09:18:52 +0000
commita7abbf4ddc70068620e9f44b74dc162ce2e16ee2 (patch)
tree74f66253717515d364ce74bd8275015c1f829cbc /src/core/utils/apiOdoo.js
parent90e1edab9b6a8ccc09a49fed3addbec2cbc4e4c3 (diff)
parenta1b9b647a6c4bda1f5db63879639d44543f9557e (diff)
Merged in refactor (pull request #1)
Refactor
Diffstat (limited to 'src/core/utils/apiOdoo.js')
-rw-r--r--src/core/utils/apiOdoo.js44
1 files changed, 0 insertions, 44 deletions
diff --git a/src/core/utils/apiOdoo.js b/src/core/utils/apiOdoo.js
deleted file mode 100644
index 4d0adae3..00000000
--- a/src/core/utils/apiOdoo.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import { getCookie, setCookie } from 'cookies-next';
-import axios from 'axios';
-import { getAuth } from './auth';
-
-const renewToken = async () => {
- let token = await axios.get(process.env.SELF_HOST + '/api/token');
- setCookie('token', token.data);
- return token.data;
-};
-
-const getToken = async () => {
- let token = getCookie('token');
- if (token == undefined) token = await renewToken();
- return token;
-};
-
-let connectionTry = 0;
-const apiOdoo = async (method, url, data = {}, headers = {}) => {
- try {
- connectionTry++;
- let token = await getToken();
- let axiosParameter = {
- method,
- url: process.env.ODOO_HOST + url,
- headers: {'Authorization': token, ...headers}
- }
- const auth = getAuth();
-
- if (auth) axiosParameter.headers['Token'] = auth.token;
- if (method.toUpperCase() == 'POST') axiosParameter.headers['Content-Type'] = 'application/x-www-form-urlencoded';
- if (Object.keys(data).length > 0) axiosParameter.data = new URLSearchParams(Object.entries(data)).toString();
-
- let res = await axios(axiosParameter);
- if (res.data.status.code == 401 && connectionTry < 15) {
- await renewToken();
- return apiOdoo(method, url, data, headers);
- }
- return res.data.result || [];
- } catch (error) {
- console.log(error)
- }
-}
-
-export default apiOdoo; \ No newline at end of file