From 8355bcb96b2dd6dcbe33f027706f2c71c5d1919d Mon Sep 17 00:00:00 2001 From: Matthew Patrick Date: Thu, 18 Nov 2021 14:08:18 +0700 Subject: [PATCH] Test Commit --- controllers/controllers.js | 101 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/controllers/controllers.js b/controllers/controllers.js index cdec7b9..9f0ab70 100644 --- a/controllers/controllers.js +++ b/controllers/controllers.js @@ -1,71 +1,76 @@ -const axios = require('axios'); +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'; +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)); } module.exports = { - getProducts, - getProduct, - register, - login, - verify_mail -} \ No newline at end of file + getProducts, + getProduct, + register, + login, + verify_mail, +};