92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
|
import React, {Component} from 'react';
|
||
|
import {readUser} from './AuthApi'
|
||
|
|
||
|
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,
|
||
|
getActifsUrl
|
||
|
} from "./IlinkConstants"
|
||
|
import {store} from "../redux/store";
|
||
|
|
||
|
var serializeJSON = function (data) {
|
||
|
return Object.keys(data).map(function (keyName) {
|
||
|
return encodeURIComponent(keyName) + '=' + encodeURIComponent(data[keyName])
|
||
|
}).join('&');
|
||
|
}
|
||
|
|
||
|
export const listAllMembers = async () => {
|
||
|
const user = await readUser();
|
||
|
if (user !== null) {
|
||
|
let la = I18n.currentLocale()
|
||
|
let data = {
|
||
|
"tag": "member",
|
||
|
"id": user.code_membre,
|
||
|
la,
|
||
|
"test": isDebugMode,
|
||
|
"codeparrain": user.code_membre
|
||
|
, "type": 'all_geolocated'
|
||
|
};
|
||
|
|
||
|
console.log("DATA to SEND", data);
|
||
|
|
||
|
const response = await fetch(memberActionUrl, {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
},
|
||
|
body: JSON.stringify(data),
|
||
|
})
|
||
|
let responseText = ""
|
||
|
try {
|
||
|
responseText = await response.text()
|
||
|
return JSON.parse(responseText)
|
||
|
} catch (e) {
|
||
|
console.log(e)
|
||
|
console.log("error when liste member", responseText)
|
||
|
let er = {
|
||
|
error: -3,
|
||
|
content: e,
|
||
|
text: responseText
|
||
|
}
|
||
|
return er;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return null
|
||
|
}
|
||
|
|
||
|
export const listAllActifs = async () => {
|
||
|
const user = await readUser();
|
||
|
const auth = store.getState().authKeyReducer;
|
||
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
||
|
if (user !== null) {
|
||
|
console.log("Get Actif URL", `${getActifsUrl}/${user.agentId}`);
|
||
|
const response = await fetch(`${getActifsUrl}/${user.agentId}`, {
|
||
|
method: 'GET',
|
||
|
headers: {
|
||
|
Accept: 'application/json',
|
||
|
'Authorization': authKey,
|
||
|
'X-Localization': I18n.currentLocale()
|
||
|
}
|
||
|
});
|
||
|
let responseText = "";
|
||
|
console.warn(response);
|
||
|
try {
|
||
|
responseText = await response.text()
|
||
|
return JSON.parse(responseText);
|
||
|
} catch (err) {
|
||
|
console.log(err);
|
||
|
return err;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|