Files

48 lines
2.0 KiB
JavaScript

import axios from "axios";
//axios.defaults.headers.common = { 'X-Requested-With': 'XMLHttpRequest' }
axios.defaults.baseURL = (process.env.NODE_ENV !== 'production') ? 'http://localhost/app_dev.php/' : ''
export default {
user: {
login: credentials =>
axios.post("/api/login_check", { username: credentials.email, password: credentials.password }).then(res => res.data),
loginOauth: ({token,type}) =>
axios.post("/api/login_check_oauth", {'oauth-token':token,'oauth-type':type}),
fetchUser: () =>{
console.log("axios /api/user")
return axios.get("/api/user").then(res => {console.log(res); return res.data})},
subscribeToNewsletter: (data) =>
{
console.log(data)
return axios.post("http://localhost:3000/NewsletterSubscription", data).then(res => {console.log(res); return res})
},
register: (data) => {
console.log(data)
return axios.post("/api/register", { data}).then(res => res)
},
},
ads: {
fetchAd: (id) => {
console.debug("--- fetchAd")
console.debug(id)
return axios.get(`api/ads/${id}`).then(res => res.data)
},
//offset is the index position of the first element to start requesting at
// use 0|1 for isPromoted
fetchAds: ({ limit = null, order = "", keyword = "", offset = 1, status='PUBLISHED', isPromoted=null}) => {
console.debug("--- fetchAds" + offset, limit, order, keyword)
return axios.get('api/ads', { params: { offset, limit, order, keyword, status, isPromoted } })
.then(res => res.data)
},
},
companies: {
fetchCompany: id =>
axios.get(`api/companies/${id}`).then(res => res.data),
fetchCompanies: (limit = "", order = "", keyword = "", offset = 1) =>
axios.get('api/companies', { params: { offset, limit, order, keyword } }).then(res => res.data)
}
};