1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import {dbUrl} from "./../config/variables";
- export const fetchPathKeys = () => {
- return fetch(dbUrl + "/get-path")
- .then(res => {
- if(res.status >= 400) {
- throw new Error("Server responds with error!");
- }
- return res.json();
- }).then(data => {
- return Object.keys(data)
- }, err => {
- console.log(err)
- });
- }
- export const fetchPaths = () => {
- return fetch(dbUrl + "/get-path")
- .then(res => {
- if(res.status >= 400) {
- throw new Error("Server responds with error!");
- }
- return res.json();
- }).then(data => {
- return data
- }, err => {
- console.log(err)
- })
- }
- export function savePathToDb(){
- let path = this.props.path
- if ("switchLatLng" in this.props){
- path = path.map(pos => [pos[1], pos[0]])
- }
- let json = JSON.stringify({
- path: {
- name: this.state.savePathKey,
- coords: path
- }
- })
- let reqOptions = {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: json
- }
- return fetch(dbUrl + "/set-path", reqOptions)
- .then(res => {
- if(res.status >= 400) {
- throw new Error("Server responds with error!");
- }
- return res.text();
- }, err => {
- console.log(err)
- })
- }
- export function saveTimeToDb(data){
- let json = JSON.stringify(data)
- let reqOptions = {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: json
- }
- return fetch(dbUrl + "/set-time", reqOptions)
- .then(res => {
- if(res.status >= 400) {
- console.log(res.text)
- throw new Error("Server responds with error!");
- }
- return res.text();
- }, err => {
- console.log(err)
- })
- }
|