-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartDataFetch.js
57 lines (54 loc) · 2.2 KB
/
chartDataFetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import axios from 'axios'
import { reject } from 'q'
import store from './src/store'
const dateAux = new Date()
//CONSERTAR PARA PRODUÇÃO
export default{
dateChartFetch(date){
return new Promise((resolve, reject) =>{
axios
.get(`https://mongo-lora-gutem.herokuapp.com/temptopic/${date}`)
.then(resp => {
resolve ({
labels: resp.data.map(v => v.hour).sort(),
datasets: [{
label: 'Temperatura em C°',
data: resp.data.map(v => v.value),
backgroundColor: '#FA7C9126',
borderColor: '#FA7C91',
fill: true,
pointRadius: 1.5
}]
})
})
.catch((err)=>{reject(err)})
})
},
dateList(){
return new Promise((resolve, reject) =>{
axios
.get('https://mongo-lora-gutem.herokuapp.com/temptopic')
.then(resp => resolve([... new Set(resp.data.map(v => v.date))]))
.catch(err => reject(err))
})
},
fetcher(dataLabel, resource = 'temptopic'){
return new Promise((resolve, reject) =>{
let url = (resource === 'temptopic' ? `https://mongo-lora-gutem.herokuapp.com/${resource}/${dateAux.getDate()}-${(dateAux.getMonth() + 1)}-${dateAux.getFullYear()}` : `https://mongo-lora-gutem.herokuapp.com/${resource}`)
axios
.get(url)
.then(resp=>{
if (resource == 'temptopic') store.dispatch('recoverLastPacket', resp.data[resp.data.length - 1]);
else if(resource == 'ratingtopic') store.dispatch('recoverLastRate', resp.data[resp.data.length - 1]);
resolve ({
labels: resp.data.map(v => v.hour).sort(),
datasets: [{
label: dataLabel,
data: resp.data.map(v => v.value)
}]
})
})
.catch(err=> reject(err))
})
}
}