Passed
Push — master ( 8dcbad...e6bdec )
by Christian
12:34 queued 12s
created

UserApiService.updateUser   A

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
dl 0
loc 13
rs 9.95
1
import ApiService from '../api.service';
2
3
/**
4
 * Gateway for the API end point "user"
5
 * @class
6
 * @extends ApiService
7
 */
8
class UserApiService extends ApiService {
9
    constructor(httpClient, loginService, apiEndpoint = 'user') {
10
        super(httpClient, loginService, apiEndpoint);
11
        this.name = 'userService';
12
    }
13
14
    /**
15
     * Get information of the logged in user
16
     *
17
     * @param {Object} [additionalParams = {}]
18
     * @param {Object} [additionalHeaders = {}]
19
     * @returns {Promise<T>}
20
     */
21
    getUser(additionalParams = {}, additionalHeaders = {}) {
22
        const params = additionalParams;
23
        const headers = this.getBasicHeaders(additionalHeaders);
24
25
        return this.httpClient
26
            .get('/_info/me', {
27
                params,
28
                headers
29
            })
30
            .then((response) => {
31
                return ApiService.handleResponse(response);
32
            });
33
    }
34
35
    /**
36
     * Update information of the logged in user
37
     *
38
     * @param {Object} [additionalParams = {}]
39
     * @param {Object} [additionalHeaders = {}]
40
     * @returns {Promise<T>}
41
     */
42
    updateUser(additionalParams = {}, additionalHeaders = {}) {
43
        const data = additionalParams;
44
        const headers = this.getBasicHeaders(additionalHeaders);
45
46
        return this.httpClient
47
            .patch('/_info/me', data,
48
                {
49
                    headers
50
                })
51
            .then((response) => {
52
                return ApiService.handleResponse(response);
53
            });
54
    }
55
}
56
57
export default UserApiService;
58