summaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/AuthService.js34
-rw-r--r--src/services/ChatService.js17
-rw-r--r--src/services/CommandsService.js21
-rw-r--r--src/services/NotifyErrorService.js20
4 files changed, 63 insertions, 29 deletions
diff --git a/src/services/AuthService.js b/src/services/AuthService.js
index 758157c..2f58076 100644
--- a/src/services/AuthService.js
+++ b/src/services/AuthService.js
@@ -1,25 +1,8 @@
1import axios from "axios"; 1import axios from "axios";
2import Vue from 'vue' 2import error_notify from './NotifyErrorService.js'
3 3
4const url = 'http://localhost:8000/api/auth/' 4const url = 'http://localhost:8000/api/auth/'
5 5
6const error_notify = (error) => {
7 for (const [key, values] of Object.entries(error.response.data)) {
8 console.log(values)
9 values.forEach(value => {
10 Vue.notify({
11 type: 'error',
12 title: value,
13 text: (key !== 'non_field_errors') ? key : ''
14 })
15 })
16 }
17 return {
18 data: error.response.data,
19 status: error.response.status
20 }
21}
22
23export default { 6export default {
24 async login(data) { 7 async login(data) {
25 return await axios 8 return await axios
@@ -46,6 +29,19 @@ export default {
46 29
47 }, 30 },
48 31
32 async info(data) {
33 return await axios
34 .get(url+'info/?'+data)
35 .then(res => {
36 return {
37 data: res.data,
38 status: res.status
39 }
40 })
41 .catch(error => error_notify(error))
42
43 },
44
49 async logout() { 45 async logout() {
50 return await axios 46 return await axios
51 .post(url+'logout/') 47 .post(url+'logout/')
@@ -56,4 +52,4 @@ export default {
56 }) 52 })
57 .catch(error => error_notify(error)) 53 .catch(error => error_notify(error))
58 } 54 }
59} \ No newline at end of file 55}
diff --git a/src/services/ChatService.js b/src/services/ChatService.js
new file mode 100644
index 0000000..ab1e6c2
--- /dev/null
+++ b/src/services/ChatService.js
@@ -0,0 +1,17 @@
1import axios from "axios";
2import error_notify from './NotifyErrorService.js'
3
4const url = 'http://localhost:8000/api/chat/'
5
6export default {
7 async group_create(data) {
8 return await axios
9 .post(url+'groups/', data)
10 .then(res => {
11 return {
12 status: res.status
13 }
14 })
15 .catch(error => error_notify(error))
16 }
17}
diff --git a/src/services/CommandsService.js b/src/services/CommandsService.js
index f8a815f..01a758e 100644
--- a/src/services/CommandsService.js
+++ b/src/services/CommandsService.js
@@ -3,18 +3,19 @@ import store from "@/store/index.js"
3import router from '@/router/index.js' 3import router from '@/router/index.js'
4 4
5export default { 5export default {
6 logout() { 6 groups() {
7 return {
8 send(searcher) {console.log(searcher)},
9
10 make(searcher) {
11 searcher.$emit('toogle_group_maker')
12 },
13 }
14 },
15
16 logout() {
7 AuthService.logout() 17 AuthService.logout()
8 store.dispatch('logout') 18 store.dispatch('logout')
9 router.push('/login') 19 router.push('/login')
10 }, 20 },
11 friends() {
12 console.log("list")
13 },
14 tab() {
15 return {
16 on() {},
17 off() {}
18 }
19 }
20} 21}
diff --git a/src/services/NotifyErrorService.js b/src/services/NotifyErrorService.js
new file mode 100644
index 0000000..b28e664
--- /dev/null
+++ b/src/services/NotifyErrorService.js
@@ -0,0 +1,20 @@
1import Vue from 'vue'
2
3const error_notify = (error) => {
4 for (const [key, values] of Object.entries(error.response.data)) {
5 console.log(values)
6 values.forEach(value => {
7 Vue.notify({
8 type: 'error',
9 title: value,
10 text: (key !== 'non_field_errors') ? key : ''
11 })
12 })
13 }
14 return {
15 data: error.response.data,
16 status: error.response.status
17 }
18}
19
20export default error_notify