2020-06-12 11:13:59 +00:00
|
|
|
|
2020-06-23 08:55:19 +00:00
|
|
|
import { createIdentificationUrl, validateIdentificationUrl, getNumberInformationUrl, getUserIdentifiedInformationUrl } from "./IlinkConstants";
|
2020-06-12 11:13:59 +00:00
|
|
|
import { store } from "../redux/store";
|
|
|
|
import axios from "axios";
|
|
|
|
import I18n from 'react-native-i18n'
|
2020-06-23 08:55:19 +00:00
|
|
|
import { fetchCreateIdentificationReset, fetchCreateIdentificationSuccess, fetchCreateIdentificationError, fetchCreateIdentificationPending, fetchGetNumberInformationPending, fetchGetNumberInformationSuccess, fetchGetNumberInformationError, fetchGetNumberInformationReset, fetchUserIdentificationPending, fetchUserIdentificationSuccess, fetchUserIdentificationError, fetchUserIdentificationReset, fetchValidateIndentificationPending, fetchValidateIndentificationSuccess, fetchValidateIndentificationError, fetchValidateIndentificationReset } from "../redux/actions/IdentificationAction";
|
2020-06-16 09:25:46 +00:00
|
|
|
|
2020-06-12 11:13:59 +00:00
|
|
|
|
|
|
|
export const createIndentificationAction = (data) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchCreateIdentificationPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${createIdentificationUrl}`,
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
},
|
|
|
|
data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchCreateIdentificationSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
//dispatch(fetchCreateIdentificationError(error.message));
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchCreateIdentificationError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchCreateIdentificationError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchCreateIdentificationError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 09:42:31 +00:00
|
|
|
export const updateIndentificationAction = (data) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchCreateIdentificationPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${createIdentificationUrl}`,
|
|
|
|
method: 'PUT',
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
},
|
|
|
|
data
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchCreateIdentificationSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
//dispatch(fetchCreateIdentificationError(error.message));
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchCreateIdentificationError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchCreateIdentificationError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchCreateIdentificationError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 11:13:59 +00:00
|
|
|
export const createIndentificationResetAction = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchCreateIdentificationReset());
|
|
|
|
}
|
2020-06-16 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getNumberDetailAction = (number) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchGetNumberInformationPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${getNumberInformationUrl}/${number}`,
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchGetNumberInformationSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchGetNumberInformationError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchGetNumberInformationError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchGetNumberInformationError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getNumberResetAction = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchGetNumberInformationReset());
|
|
|
|
}
|
2020-06-17 14:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getUserIdentificationAction = (userID) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchUserIdentificationPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${getUserIdentifiedInformationUrl}/${userID}`,
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchUserIdentificationSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchUserIdentificationError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchUserIdentificationError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchUserIdentificationError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getUserIdentificationResetAction = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchUserIdentificationReset());
|
|
|
|
}
|
2020-06-23 08:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const validateIdentificationAction = (formData, idIdentification) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchValidateIndentificationPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${validateIdentificationUrl}/${idIdentification}`,
|
|
|
|
method: 'POST',
|
|
|
|
data: formData,
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchValidateIndentificationSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchValidateIndentificationError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchValidateIndentificationError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchValidateIndentificationError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const validateIdentificationResetAction = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchValidateIndentificationReset());
|
|
|
|
}
|
2020-06-12 11:13:59 +00:00
|
|
|
}
|