2022-10-05 18:03:52 +02:00
|
|
|
// Lodash
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
// Http Client
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
// Network Infos
|
|
|
|
|
import NetInfo from "@react-native-community/netinfo";
|
|
|
|
|
// Application infos
|
|
|
|
|
import * as Application from 'expo-application';
|
|
|
|
|
// Database
|
2022-10-06 10:28:41 +02:00
|
|
|
import { Setting, Contact, SendBrochure } from '../../Database';
|
2022-10-05 18:03:52 +02:00
|
|
|
|
|
|
|
|
const api_token = 'toto';
|
|
|
|
|
const app_uuid = '1f6eda31-1f6d-49fe-aa81-4f0aece0f7ca';
|
|
|
|
|
const url = "https://dev-app.rhd-ldc.fr";
|
|
|
|
|
|
|
|
|
|
class SyncController {
|
|
|
|
|
|
|
|
|
|
async checkConnection() {
|
|
|
|
|
NetInfo.fetch().then(state => {
|
|
|
|
|
return state.isConnected;
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getVersion() {
|
|
|
|
|
return axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/version',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token,
|
|
|
|
|
app_uuid: app_uuid,
|
|
|
|
|
app_version: Application.nativeApplicationVersion
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getUsers() {
|
|
|
|
|
return axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/users',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 10:28:41 +02:00
|
|
|
async getContacts(userId) {
|
|
|
|
|
let contacts = Contact.getAll();
|
|
|
|
|
return axios({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: url + '/api/contacts',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
contacts: contacts,
|
|
|
|
|
userId: userId,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async sendBrochures() {
|
|
|
|
|
let brochures = SendBrochure.getAll();
|
|
|
|
|
for (const brochure of brochures) {
|
|
|
|
|
await axios({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: url + '/api/sendBrochure',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token,
|
|
|
|
|
emails: brochure,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
SendBrochure.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getDirectories() {
|
|
|
|
|
return axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: url + '/api/directories',
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
params: {
|
|
|
|
|
token: api_token
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 18:03:52 +02:00
|
|
|
updateShowIsActive(value) {
|
|
|
|
|
const local = Setting.get('ShowIsActive');
|
|
|
|
|
if (local === false || local === undefined) {
|
|
|
|
|
Setting.add({ key: 'ShowIsActive', value: value });
|
|
|
|
|
} else {
|
|
|
|
|
Setting.update({ id: local.id, key: 'ShowIsActive', value: value });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new SyncController();
|