2021-11-16 00:43:50 +01:00
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
let config;
|
|
|
|
try {
|
|
|
|
config = require('../config');
|
|
|
|
} catch (e) {
|
|
|
|
console.log('No config file found');
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const HOST = config.host + '/api';
|
|
|
|
|
|
|
|
function getProducts() {
|
|
|
|
return axios.get(HOST + '/getproducts')
|
|
|
|
.then(response => response.data)
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProduct(id) {
|
|
|
|
return axios.get(HOST + '/getproduct', { params: { id: id } })
|
|
|
|
.then(response => response.data)
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
2021-11-16 07:19:35 +01:00
|
|
|
function register(email, password, first_name, last_name) {
|
|
|
|
let params = new URLSearchParams({
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
|
|
|
'first_name': first_name,
|
|
|
|
'last_name': last_name
|
|
|
|
})
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return axios.post(HOST + '/register', params, conf)
|
|
|
|
.then(response => response.status)
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
2021-11-17 09:22:25 +01:00
|
|
|
function login(email, password, ua, ip) {
|
|
|
|
let params = new URLSearchParams({
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
|
|
|
'ua': ua,
|
|
|
|
'ip': ip
|
|
|
|
})
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return axios.post(HOST + '/login', params, conf)
|
|
|
|
.then(response => [response.status, response.data])
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
|
|
|
|
2021-11-16 00:43:50 +01:00
|
|
|
module.exports = {
|
|
|
|
getProducts,
|
2021-11-16 07:19:35 +01:00
|
|
|
getProduct,
|
2021-11-17 09:22:25 +01:00
|
|
|
register,
|
|
|
|
login
|
2021-11-16 00:43:50 +01:00
|
|
|
}
|