Skip to content

Commit c8d1646

Browse files
committed
WIP
1 parent 574a6f6 commit c8d1646

23 files changed

Lines changed: 358 additions & 72 deletions

File tree

generator/templates/Authorisation/src/api/authorisation/login.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

generator/templates/Authorisation/src/api/authorisation/logout.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

generator/templates/Authorisation/src/api/authorisation/register.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {post} from '../../implementation/app/wrapper.js';
2+
3+
export default function () {
4+
return post('auth/logout');
5+
}
6+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {post} from '../../implementation/app/wrapper.js';
2+
3+
function passwordForgotten(email) {
4+
return post('password/forgotten', {
5+
email: email,
6+
});
7+
}
8+
9+
function passwordReset(token, email, password, passwordConfirmation) {
10+
return post('password/reset', {
11+
token: token,
12+
email: email,
13+
password: password,
14+
password_confirmation: passwordConfirmation
15+
});
16+
}
17+
18+
export {
19+
passwordForgotten,
20+
passwordReset,
21+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {post} from '../../implementation/app/wrapper.js';
2+
3+
export default function (email, name) {
4+
return post('registration', {
5+
email, name,
6+
});
7+
}

generator/templates/Authorisation/src/api/password/forgotten.js renamed to generator/templates/Authorisation/src/api/endpoints/password/forgotten.js

File renamed without changes.

generator/templates/Authorisation/src/api/password/reset.js renamed to generator/templates/Authorisation/src/api/endpoints/password/reset.js

File renamed without changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import axios from 'axios';
2+
3+
import {onRequestFulFilled, onRequestRejected, onResponseFulFilled, onResponseRejected} from './interceptor';
4+
import {destroy, get, getPaginated, post, put} from './wrapper';
5+
6+
/**
7+
* Returns an axios instance
8+
* specifically made for app API calls.
9+
*/
10+
11+
/**
12+
* @type {AxiosRequestConfig}
13+
*/
14+
const config = {
15+
baseURL: process.env.VUE_APP_ROOT_API,
16+
headers: {
17+
Accept: 'application/json',
18+
},
19+
};
20+
21+
const instance = axios.create(config);
22+
23+
instance.interceptors.request.use(onRequestFulFilled, onRequestRejected);
24+
instance.interceptors.response.use(onResponseFulFilled, onResponseRejected);
25+
26+
export {
27+
get,
28+
getPaginated,
29+
post,
30+
put,
31+
destroy,
32+
}
33+
34+
export default instance;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import store from '../../../store';
2+
3+
/**
4+
* @param request {AxiosRequestConfig}
5+
*/
6+
function onRequestFulFilled(request) {
7+
return request;
8+
}
9+
10+
/**
11+
* @param error {AxiosError}
12+
*/
13+
function onRequestRejected(error) {
14+
return error;
15+
}
16+
17+
/**
18+
* @param response {AxiosResponse}
19+
*/
20+
function onResponseFulFilled(response) {
21+
return response;
22+
}
23+
24+
/**
25+
* @param error {AxiosError}
26+
*/
27+
function onResponseRejected(error) {
28+
29+
if (typeof error === 'string' || !error.response) return Promise.reject(error);
30+
31+
const status = error.response.status;
32+
33+
const data = error.response.data;
34+
/* Now we know there was an error during submitting */
35+
if (data.errors && status === 422) {
36+
/* For now, all errors will be removed on route change
37+
* We might need to add global errors later on */
38+
Object.keys(data.errors).forEach(key => store.commit('Error/add', {
39+
key: key,
40+
message: data.errors[key][0],
41+
}));
42+
}
43+
44+
return Promise.reject(error.response);
45+
}
46+
47+
export {
48+
onRequestFulFilled,
49+
onRequestRejected,
50+
onResponseFulFilled,
51+
onResponseRejected,
52+
};

0 commit comments

Comments
 (0)