123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import axios from 'axios';
- export class Service {
- constructor(path) {
- this.base_url = 'http://204.48.25.93:8081'
- this.url = this.base_url + path
- // this.base_url = 'http://psicoadmin.ditca.org:8081'
- // this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
- // this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
- }
- async getQuery(token) {
- return await axios.get(this.url, {
- headers: {
- 'Authorization': `Bearer ${token}`
- }
- })
- }
- async get(token) {
- return axios.get(this.url, {
- headers: {
- 'Authorization': `Bearer ${token}`
- }
- })
- .then((res) => {
- return res;
- })
- .catch((error) => {
- console.log("ERROR :: ", error)
- return new Error("GG");
- })
- }
- async post(body, token) {
- if (!token) {
- let response = await axios({
- method: "POST",
- url: this.url,
- headers: {
- 'Content-Type': 'application/json',
- },
- data: body
- })
- return await response.data;
- }
- const MyHeaders = {
- 'Authorization': 'Bearer ' + token,
- }
- let response = await axios({
- method: "POST",
- url: this.url,
- headers: MyHeaders,
- data: body
- })
- console.log('response', response)
- return await response.data;
- }
- async postQuery(body, token) {
- if (!token) {
- return await axios({
- method: "POST",
- url: this.url,
- headers: {
- 'Content-Type': 'application/json',
- },
- data: body
- })
- }
- const MyHeaders = {
- 'Authorization': 'Bearer ' + token,
- }
- return await axios({
- method: "POST",
- url: this.url,
- headers: MyHeaders,
- data: body
- })
- }
- async put(body, token) {
- if (!token) {
- let response = await axios({
- method: "PUT",
- url: this.url,
- headers: {
- 'Content-Type': 'application/json',
- },
- data: body
- })
- return await response.data;
- }
- const MyHeaders = {
- 'Authorization': 'Bearer ' + token,
- }
- let response = await axios({
- method: "PUT",
- url: this.url,
- headers: MyHeaders,
- data: body
- })
- console.log('response', response)
- return await response.data;
- }
- async putQuery(body, token) {
- if (!token) {
- return await axios({
- method: "PUT",
- url: this.url,
- headers: {
- 'Content-Type': 'application/json',
- },
- data: body
- })
- }
- const MyHeaders = {
- 'Authorization': 'Bearer ' + token,
- }
- return await axios({
- method: "PUT",
- url: this.url,
- headers: MyHeaders,
- data: body
- })
- }
- }
|