diff options
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/AuthService.js | 34 | ||||
-rw-r--r-- | src/services/ChatService.js | 17 | ||||
-rw-r--r-- | src/services/CommandsService.js | 21 | ||||
-rw-r--r-- | src/services/NotifyErrorService.js | 20 |
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 @@ | |||
1 | import axios from "axios"; | 1 | import axios from "axios"; |
2 | import Vue from 'vue' | 2 | import error_notify from './NotifyErrorService.js' |
3 | 3 | ||
4 | const url = 'http://localhost:8000/api/auth/' | 4 | const url = 'http://localhost:8000/api/auth/' |
5 | 5 | ||
6 | const 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 | |||
23 | export default { | 6 | export 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 @@ | |||
1 | import axios from "axios"; | ||
2 | import error_notify from './NotifyErrorService.js' | ||
3 | |||
4 | const url = 'http://localhost:8000/api/chat/' | ||
5 | |||
6 | export 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" | |||
3 | import router from '@/router/index.js' | 3 | import router from '@/router/index.js' |
4 | 4 | ||
5 | export default { | 5 | export 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 @@ | |||
1 | import Vue from 'vue' | ||
2 | |||
3 | const 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 | |||
20 | export default error_notify | ||