2021-11-18 08:08:18 +01:00
|
|
|
const axios = require("axios");
|
2021-11-16 00:43:50 +01:00
|
|
|
|
|
|
|
let config;
|
|
|
|
try {
|
2021-11-20 03:09:20 +01:00
|
|
|
config = require("../config");
|
2021-11-16 00:43:50 +01:00
|
|
|
} catch (e) {
|
2021-11-20 03:09:20 +01:00
|
|
|
console.log("No config file found");
|
|
|
|
process.exit(0);
|
2021-11-16 00:43:50 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 08:08:18 +01:00
|
|
|
const HOST = config.host + "/api";
|
2021-11-16 00:43:50 +01:00
|
|
|
|
|
|
|
function getProducts() {
|
2021-11-20 03:09:20 +01:00
|
|
|
return axios
|
|
|
|
.get(HOST + "/getproducts")
|
|
|
|
.then((response) => response.data)
|
|
|
|
.catch((error) => console.log(error));
|
2021-11-16 00:43:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getProduct(id) {
|
2021-11-20 03:09:20 +01:00
|
|
|
return axios
|
|
|
|
.get(HOST + "/getproduct", {
|
|
|
|
params: {
|
|
|
|
id: id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then((response) => response.data)
|
|
|
|
.catch((error) => console.log(error));
|
2021-11-16 00:43:50 +01:00
|
|
|
}
|
|
|
|
|
2021-11-16 07:19:35 +01:00
|
|
|
function register(email, password, first_name, last_name) {
|
2021-11-20 03:09:20 +01:00
|
|
|
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) => [error.status, []]);
|
2021-11-16 07:19:35 +01:00
|
|
|
}
|
|
|
|
|
2021-11-17 09:22:25 +01:00
|
|
|
function login(email, password, ua, ip) {
|
2021-11-20 03:09:20 +01:00
|
|
|
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) => [error.status, []]);
|
2021-11-17 09:22:25 +01:00
|
|
|
}
|
|
|
|
|
2021-11-17 09:52:36 +01:00
|
|
|
function verify_mail(token) {
|
2021-11-21 01:26:36 +01:00
|
|
|
let params = new URLSearchParams({
|
|
|
|
token: token,
|
|
|
|
});
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
},
|
|
|
|
};
|
2021-11-20 03:09:20 +01:00
|
|
|
return axios
|
2021-11-21 01:26:36 +01:00
|
|
|
.post(HOST + "/verify-mail", params, conf)
|
|
|
|
.then((response) => [response.status, response.data])
|
|
|
|
.catch((error) => [error.status, []]);
|
2021-11-20 03:09:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 07:40:23 +01:00
|
|
|
function request_reset_password(email) {
|
|
|
|
let params = new URLSearchParams({
|
|
|
|
email: email,
|
|
|
|
});
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return axios
|
|
|
|
.post(HOST + "/request-reset-password", params, conf)
|
|
|
|
.then((response) => [response.status, response.data])
|
|
|
|
.catch((error) => [error.status, []]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_password(
|
|
|
|
token,
|
|
|
|
password
|
|
|
|
) {
|
|
|
|
let params = new URLSearchParams({
|
|
|
|
password: password,
|
|
|
|
});
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
},
|
|
|
|
params: {
|
|
|
|
token: token,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return axios
|
|
|
|
.post(HOST + "/reset-password", params, conf)
|
|
|
|
.then((response) => [response.status, response.data])
|
|
|
|
.catch((error) => [error.status, []]);
|
|
|
|
}
|
|
|
|
|
2021-11-20 03:09:20 +01:00
|
|
|
function checkout(
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
phoneNumber,
|
|
|
|
streetAddress1,
|
|
|
|
streetAddress2,
|
|
|
|
region,
|
|
|
|
province,
|
|
|
|
city,
|
|
|
|
district,
|
|
|
|
subDistrict,
|
|
|
|
postalCode,
|
|
|
|
logistic,
|
2021-11-21 02:16:15 +01:00
|
|
|
data,
|
|
|
|
key
|
2021-11-20 03:09:20 +01:00
|
|
|
) {
|
|
|
|
let params = new URLSearchParams({
|
|
|
|
firstName: firstName,
|
|
|
|
lastName: lastName,
|
|
|
|
phoneNumber: phoneNumber,
|
|
|
|
streetAddress1: streetAddress1,
|
|
|
|
streetAddress2: streetAddress2,
|
|
|
|
region: region,
|
|
|
|
province: province,
|
|
|
|
city: city,
|
|
|
|
district: district,
|
|
|
|
subDistrict: subDistrict,
|
|
|
|
postalCode: postalCode,
|
|
|
|
logistic: logistic,
|
|
|
|
data: data,
|
|
|
|
});
|
|
|
|
const conf = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
},
|
2021-11-21 02:16:15 +01:00
|
|
|
params: {
|
|
|
|
key: key,
|
|
|
|
}
|
2021-11-20 03:09:20 +01:00
|
|
|
};
|
|
|
|
return axios
|
|
|
|
.post(HOST + "/checkout", params, conf)
|
|
|
|
.then((response) => [response.status, response.data])
|
|
|
|
.catch((error) => [error.status, []]);
|
2021-11-17 09:52:36 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 03:57:12 +01:00
|
|
|
function transaction(key) {
|
|
|
|
const conf = {
|
|
|
|
params: {
|
|
|
|
key: key,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return axios
|
|
|
|
.post(HOST + "/transaction", null, conf)
|
|
|
|
.then((response) => [response.status, response.data])
|
|
|
|
.catch((error) => [error.status, []]);
|
|
|
|
}
|
|
|
|
|
2021-11-16 00:43:50 +01:00
|
|
|
module.exports = {
|
2021-11-20 03:09:20 +01:00
|
|
|
getProducts,
|
|
|
|
getProduct,
|
|
|
|
register,
|
|
|
|
login,
|
|
|
|
verify_mail,
|
2021-11-21 07:40:23 +01:00
|
|
|
request_reset_password,
|
|
|
|
reset_password,
|
2021-11-21 03:57:12 +01:00
|
|
|
checkout,
|
|
|
|
transaction
|
2021-11-20 03:09:20 +01:00
|
|
|
};
|