ilink-world/webservice/HistoryRequestApi.js

147 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-06-16 13:09:54 +00:00
import React, { Component } from 'react';
2020-05-01 22:36:24 +00:00
var DBEvents = require('react-native-db-models').DBEvents;
var db = require('./persistences/db.js');
2019-06-16 13:09:54 +00:00
import I18n from 'react-native-i18n'
2020-05-01 22:36:24 +00:00
import { isDebugMode, adhesionUrl, locationActionUrl, memberActionUrl, networkActionUrl, demandeActionUrl } from "./IlinkConstants"
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
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 };
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
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 [];
}
2019-06-16 13:09:54 +00:00
}
2020-05-01 22:36:24 +00:00
export const loadMyDemandeCredit = async () => {
const user = await readUser();
console.log("USER ID", user.agentId);
const data = {
"tag": "credit_demands_of_agent", id: user.agentId
, "lang": I18n.currentLocale(),
test: isDebugMode
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
};
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 [];
}
2019-06-16 13:09:54 +00:00
}
2020-05-01 22:36:24 +00:00
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) })
2019-06-16 13:09:54 +00:00
}
2020-05-01 22:36:24 +00:00
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
};
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
let response = await fetch(demandeActionUrl, {
2019-06-16 13:09:54 +00:00
method: 'POST',
headers: {
2020-05-01 22:36:24 +00:00
Accept: 'application/json',
'Content-Type': 'application/json',
2019-06-16 13:09:54 +00:00
},
body: JSON.stringify(data),
2020-05-01 22:36:24 +00:00
})
let responseTxt = "";
try {
responseTxt = await response.text()
let responseJson = JSON.parse(responseTxt)
return responseJson
} catch (e) {
console.log(response)
console.log("error", responseTxt)
return []
}
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
} else
return -1;
2019-06-16 13:09:54 +00:00
}
2020-05-01 22:36:24 +00:00
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()
};
2019-06-16 13:09:54 +00:00
2020-05-01 22:36:24 +00:00
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 []
}
2019-06-16 13:09:54 +00:00
}