mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 02:16:19 +01:00
Add checkout controllers
This commit is contained in:
parent
8ff4f43f0b
commit
4e7f5767d7
1 changed files with 101 additions and 51 deletions
|
@ -2,75 +2,125 @@ const axios = require("axios");
|
|||
|
||||
let config;
|
||||
try {
|
||||
config = require("../config");
|
||||
config = require("../config");
|
||||
} catch (e) {
|
||||
console.log("No config file found");
|
||||
process.exit(0);
|
||||
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));
|
||||
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));
|
||||
return axios
|
||||
.get(HOST + "/getproduct", {
|
||||
params: {
|
||||
id: id
|
||||
}
|
||||
})
|
||||
.then((response) => response.data)
|
||||
.catch((error) => console.log(error));
|
||||
}
|
||||
|
||||
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) => [error.status, []]);
|
||||
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, []]);
|
||||
}
|
||||
|
||||
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) => [error.status, []]);
|
||||
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, []]);
|
||||
}
|
||||
|
||||
function verify_mail(token) {
|
||||
return axios
|
||||
.get(HOST + "/verify-mail", { params: { token: token } })
|
||||
.then((response) => response.status)
|
||||
.catch((error) => console.log(error));
|
||||
return axios
|
||||
.get(HOST + "/verify-mail", {
|
||||
params: {
|
||||
token: token
|
||||
}
|
||||
})
|
||||
.then((response) => response.status)
|
||||
.catch((error) => console.log(error));
|
||||
}
|
||||
|
||||
function checkout(
|
||||
firstName,
|
||||
lastName,
|
||||
phoneNumber,
|
||||
streetAddress1,
|
||||
streetAddress2,
|
||||
region,
|
||||
province,
|
||||
city,
|
||||
district,
|
||||
subDistrict,
|
||||
postalCode,
|
||||
logistic,
|
||||
data
|
||||
) {
|
||||
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",
|
||||
},
|
||||
};
|
||||
return axios
|
||||
.post(HOST + "/checkout", params, conf)
|
||||
.then((response) => [response.status, response.data])
|
||||
.catch((error) => [error.status, []]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getProducts,
|
||||
getProduct,
|
||||
register,
|
||||
login,
|
||||
verify_mail,
|
||||
};
|
||||
getProducts,
|
||||
getProduct,
|
||||
register,
|
||||
login,
|
||||
verify_mail,
|
||||
checkout
|
||||
};
|
Loading…
Reference in a new issue