142 lines
4.1 KiB
JavaScript
142 lines
4.1 KiB
JavaScript
|
|
||
|
import React, { Component } from 'react';
|
||
|
var DBEvents=require('react-native-db-models').DBEvents;
|
||
|
var db=require('./persistences/db.js');
|
||
|
|
||
|
import I18n from 'react-native-i18n'
|
||
|
import {isDebugMode,adhesionUrl,locationActionUrl,memberActionUrl,networkActionUrl,demandeActionUrl} from "./IlinkConstants"
|
||
|
|
||
|
import {readUser} from './AuthApi'
|
||
|
export const loadDemandeCredit= async ()=>{
|
||
|
const user=await readUser();
|
||
|
const data={"tag":"credit_demands",'id':user.code_membre,"lang":I18n.currentLocale(),test:isDebugMode};
|
||
|
|
||
|
const response=await fetch(demandeActionUrl ,{
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
});
|
||
|
try{
|
||
|
console.log(response)
|
||
|
let responseJson=await response.json()
|
||
|
console.log(responseJson)
|
||
|
return responseJson;
|
||
|
}catch(e){
|
||
|
console.log(response.text())
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
export const loadMyDemandeCredit= async ()=>{
|
||
|
const user=await readUser();
|
||
|
const data={"tag":"credit_demands_of_agent",id:user.agentId
|
||
|
,"lang":I18n.currentLocale(),
|
||
|
test:isDebugMode
|
||
|
|
||
|
};
|
||
|
console.log(data)
|
||
|
const response=await fetch(demandeActionUrl ,{
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
});
|
||
|
try{
|
||
|
console.log(response,"my demande")
|
||
|
let responseJson=await response.json()
|
||
|
console.log(responseJson)
|
||
|
return responseJson;
|
||
|
}catch(e){
|
||
|
return [];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
export const updateCreditDemand=(phone,id)=>{
|
||
|
const data={"tag":"update_ask_credit","phone":phone,"id":id,
|
||
|
"lang":I18n.currentLocale(),
|
||
|
test:isDebugMode
|
||
|
}
|
||
|
return fetch(demandeActionUrl,{
|
||
|
"method":"POST",
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
}).then((response)=>{
|
||
|
return response.json()
|
||
|
})
|
||
|
.then( (responseJson)=>{
|
||
|
return responseJson
|
||
|
})
|
||
|
.catch((error)=>{console.warn(error)})
|
||
|
|
||
|
}
|
||
|
|
||
|
export const sendDemande= async (credit)=>{
|
||
|
const muser=await readUser()
|
||
|
if(muser!==undefined && muser.code_parrain!==undefined
|
||
|
&& muser.code_membre!==undefined &&
|
||
|
muser.code_membre!==muser.code_parrain){
|
||
|
let data={
|
||
|
"tag":"ask_credit",
|
||
|
"phone":muser.phone,
|
||
|
"code":muser.code,
|
||
|
"lang":I18n.currentLocale(),
|
||
|
test:isDebugMode,
|
||
|
"montant":credit
|
||
|
};
|
||
|
|
||
|
let response=await fetch(demandeActionUrl,{
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
})
|
||
|
let responseTxt="";
|
||
|
try{
|
||
|
responseTxt=await response.text()
|
||
|
let responseJson=JSON.parse(responseTxt)
|
||
|
return responseJson
|
||
|
}catch(e){
|
||
|
console.log(response)
|
||
|
console.log("error",responseTxt)
|
||
|
return []
|
||
|
}
|
||
|
|
||
|
}else
|
||
|
return -1;
|
||
|
}
|
||
|
export const sendDemandeSpecificque= async (credit,phone,code_membre)=>{
|
||
|
let data={"tag":"ask_credit",
|
||
|
"phone":phone,
|
||
|
test:isDebugMode,
|
||
|
code:code_membre,
|
||
|
"montant":credit,"lang":I18n.currentLocale()};
|
||
|
|
||
|
let response=await fetch(demandeActionUrl,{
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
})
|
||
|
try{
|
||
|
let responseJson=await response.json()
|
||
|
console.log(responseJson)
|
||
|
return responseJson
|
||
|
}catch(e){
|
||
|
console.log(response)
|
||
|
console.warn(e)
|
||
|
return []
|
||
|
}
|
||
|
|
||
|
}
|