mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 18:36:20 +01:00
Add product controllers
This commit is contained in:
parent
e61a9a93e2
commit
f7e0413b32
1 changed files with 28 additions and 0 deletions
28
controllers/productController.js
Normal file
28
controllers/productController.js
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue