ilink-world/app/webservice/NanoCreditApi.js

454 lines
14 KiB
JavaScript
Raw Normal View History

2020-08-11 09:42:31 +00:00
import axios from "axios";
import I18n from 'react-native-i18n';
2020-11-11 10:18:19 +00:00
import {
fetchAskNanoCreditError,
fetchAskNanoCreditPending,
fetchAskNanoCreditReset,
fetchAskNanoCreditSuccess,
fetchCreateGroupError,
fetchCreateGroupPending,
fetchCreateGroupReset,
fetchCreateGroupSuccess,
2022-02-28 09:41:54 +00:00
fetchFacturerSoinError,
fetchFacturerSoinPending,
fetchFacturerSoinReset,
fetchFacturerSoinSuccess,
2020-11-11 10:18:19 +00:00
fetchGetEpargneInProgressError,
fetchGetEpargneInProgressPending,
fetchGetEpargneInProgressReset,
fetchGetEpargneInProgressSuccess,
fetchGetNanoCreditDemandDurationError,
fetchGetNanoCreditDemandDurationPending,
fetchGetNanoCreditDemandDurationReset,
fetchGetNanoCreditDemandDurationSuccess,
fetchGetNanoCreditUserHistoryInProgressError,
fetchGetNanoCreditUserHistoryInProgressPending,
fetchGetNanoCreditUserHistoryInProgressReset,
fetchGetNanoCreditUserHistoryInProgressSuccess,
2022-02-28 09:41:54 +00:00
fetchInvoiceHistoryError,
fetchInvoiceHistoryPending, fetchInvoiceHistoryReset,
fetchInvoiceHistorySuccess,
2020-11-11 10:18:19 +00:00
fetchJoinGroupError,
fetchJoinGroupPending,
fetchJoinGroupReset,
fetchJoinGroupSuccess,
fetchTreatDemandsGroupError,
fetchTreatDemandsGroupPending,
fetchTreatDemandsGroupReset,
fetchTreatDemandsGroupSuccess
} from "../redux/actions/NanoCreditAction";
import {store} from "../redux/store";
import {
askNanoCreditUrl,
2022-02-28 09:41:54 +00:00
cancelDemandUrl, consultationUrl, facturerSoinUrl, getHistoryEpargnePendingUrl,
2020-11-11 10:18:19 +00:00
getHistoryNanoPendingCreditUrl,
getNanoCreditDemandDureationUrl,
2022-02-28 09:41:54 +00:00
groupUrl, invoiceUrl,
2020-11-11 10:18:19 +00:00
joinGroupUrl,
treatDemandUrl
} from "./IlinkConstants";
2020-08-24 19:18:19 +00:00
/**
2020-11-11 10:18:19 +00:00
*
* @param {*} data
2020-08-24 19:18:19 +00:00
* @param {*} isToMofidy | 0-> CREATE 1->MODIFY 2->DELETE
*/
export const createGroupAction = (data, isToMofidy) => {
2020-08-11 09:42:31 +00:00
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchCreateGroupPending());
axios({
url: `${groupUrl}`,
method: isToMofidy === 0 ?
'POST' :
isToMofidy === 1 ? 'PUT' : 'DELETE',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchCreateGroupSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchCreateGroupError(error.response));
else if (error.request)
dispatch(fetchCreateGroupError(error.request))
else
dispatch(fetchCreateGroupError(error.message))
});
}
2020-08-11 09:42:31 +00:00
}
export const createGroupReset = () => {
2020-11-11 10:18:19 +00:00
return dispatch => {
dispatch(fetchCreateGroupReset());
}
2020-08-11 09:42:31 +00:00
}
2020-08-17 05:25:16 +00:00
export const treatDemandGroupAction = (data) => {
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchTreatDemandsGroupPending());
axios({
url: `${treatDemandUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchTreatDemandsGroupSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchTreatDemandsGroupError(error.response));
else if (error.request)
dispatch(fetchTreatDemandsGroupError(error.request))
else
dispatch(fetchTreatDemandsGroupError(error.message))
});
}
2020-08-24 19:18:19 +00:00
}
export const cancelDemandGroupAction = (data) => {
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchTreatDemandsGroupPending());
axios({
url: `${cancelDemandUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchTreatDemandsGroupSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchTreatDemandsGroupError(error.response));
else if (error.request)
dispatch(fetchTreatDemandsGroupError(error.request))
else
dispatch(fetchTreatDemandsGroupError(error.message))
});
}
2020-08-17 05:25:16 +00:00
}
export const treatDemandGroupReset = () => {
2020-11-11 10:18:19 +00:00
return dispatch => {
dispatch(fetchTreatDemandsGroupReset());
}
2020-08-19 06:25:24 +00:00
}
export const joinGroupAction = (data) => {
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchJoinGroupPending());
axios({
url: `${joinGroupUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchJoinGroupSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchJoinGroupError(error.response));
else if (error.request)
dispatch(fetchJoinGroupError(error.request))
else
dispatch(fetchJoinGroupError(error.message))
});
}
2020-08-19 06:25:24 +00:00
}
export const joinGroupReset = () => {
2020-11-11 10:18:19 +00:00
return dispatch => {
dispatch(fetchJoinGroupReset());
}
2020-08-27 20:04:51 +00:00
}
export const askNanoCreditAction = (data) => {
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchAskNanoCreditPending());
axios({
url: `${askNanoCreditUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchAskNanoCreditSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchAskNanoCreditError(error.response));
else if (error.request)
dispatch(fetchAskNanoCreditError(error.request))
else
dispatch(fetchAskNanoCreditError(error.message))
});
}
2020-08-27 20:04:51 +00:00
}
export const askNanoCreditReset = () => {
2020-11-11 10:18:19 +00:00
return dispatch => {
dispatch(fetchAskNanoCreditReset());
}
2020-08-27 20:04:51 +00:00
}
2020-09-15 13:53:59 +00:00
export const getNanoCreditDemandDurationAction = (data) => {
2020-08-27 20:04:51 +00:00
2020-11-11 10:18:19 +00:00
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchGetNanoCreditDemandDurationPending());
axios({
url: `${getNanoCreditDemandDureationUrl}`,
method: 'POST',
data,
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchGetNanoCreditDemandDurationSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchGetNanoCreditDemandDurationError(error.response));
else if (error.request)
dispatch(fetchGetNanoCreditDemandDurationError(error.request))
else
dispatch(fetchGetNanoCreditDemandDurationError(error.message))
});
}
2020-08-27 20:04:51 +00:00
}
export const getNanoCreditDemandDurationReset = () => {
2020-11-11 10:18:19 +00:00
return dispatch => {
dispatch(fetchGetNanoCreditDemandDurationReset());
}
}
export const getEpargneInProgressAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchGetEpargneInProgressPending());
axios({
2020-11-18 11:22:53 +00:00
url: `${getHistoryEpargnePendingUrl}/${data}`,
method: 'GET',
2020-11-11 10:18:19 +00:00
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchGetEpargneInProgressSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchGetEpargneInProgressError(error.response));
else if (error.request)
dispatch(fetchGetEpargneInProgressError(error.request))
else
dispatch(fetchGetEpargneInProgressError(error.message))
});
}
}
export const getEpargneInProgressReset = () => {
return dispatch => {
dispatch(fetchGetEpargneInProgressReset());
}
}
2022-02-28 09:41:54 +00:00
2020-11-11 10:18:19 +00:00
export const getNanoCreditUserHistoryInProgressAction = (data) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchGetNanoCreditUserHistoryInProgressPending());
axios({
url: `${getHistoryNanoPendingCreditUrl}/${data}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchGetNanoCreditUserHistoryInProgressSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.response));
else if (error.request)
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.request))
else
dispatch(fetchGetNanoCreditUserHistoryInProgressError(error.message))
});
}
}
export const getNanoCreditUserHistoryInProgressReset = () => {
return dispatch => {
dispatch(fetchGetNanoCreditUserHistoryInProgressReset());
}
2022-02-28 09:41:54 +00:00
}
export const facturerSoinAction = (otherParam) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchFacturerSoinPending());
axios({
url: `${facturerSoinUrl}${otherParam}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchFacturerSoinSuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchFacturerSoinError(error.response));
else if (error.request)
dispatch(fetchFacturerSoinError(error.request))
else
dispatch(fetchFacturerSoinError(error.message))
});
}
}
export const facturerSoinReset = () => {
return dispatch => {
dispatch(fetchFacturerSoinReset());
}
}
export const getInvoiceHistoryAction = (otherParam) => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchInvoiceHistoryPending());
axios({
url: `${invoiceUrl}${otherParam}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchInvoiceHistorySuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchInvoiceHistoryError(error.response));
else if (error.request)
dispatch(fetchInvoiceHistoryError(error.request))
else
dispatch(fetchInvoiceHistoryError(error.message))
});
}
}
export const getInvoiceHistoryReset = () => {
return dispatch => {
dispatch(fetchInvoiceHistoryReset());
}
}
export const getSoinHistoryAction = (user_id, state = 'UNTREATED', typeParam = 'CONSULTATION', otherParam = '') => {
const auth = store.getState().authKeyReducer;
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
return dispatch => {
dispatch(fetchInvoiceHistoryPending());
axios({
url: `${consultationUrl}?network_agent_id=${user_id}&state=${state}&type=${typeParam}${otherParam}`,
method: 'GET',
headers: {
'Authorization': authKey,
'X-Localization': I18n.currentLocale()
}
})
.then(response => {
console.log(response);
dispatch(fetchInvoiceHistorySuccess(response));
})
.catch(error => {
if (error.response)
dispatch(fetchInvoiceHistoryError(error.response));
else if (error.request)
dispatch(fetchInvoiceHistoryError(error.request))
else
dispatch(fetchInvoiceHistoryError(error.message))
});
}
2020-08-17 05:25:16 +00:00
}