From f7e0413b32b76804d00b67ea553e7bcc38f7871a Mon Sep 17 00:00:00 2001 From: moepoi Date: Tue, 16 Nov 2021 06:43:50 +0700 Subject: [PATCH] Add product controllers --- controllers/productController.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 controllers/productController.js diff --git a/controllers/productController.js b/controllers/productController.js new file mode 100644 index 0000000..cdb1b71 --- /dev/null +++ b/controllers/productController.js @@ -0,0 +1,28 @@ +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)) +} + +module.exports = { + getProducts, + getProduct +} \ No newline at end of file