View | Details | Raw Unified | Return to bug 32939
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (-4 / +1 lines)
Lines 24-46 export class ERMAPIClient extends HttpClient { Link Here
24
            delete: (id) =>
24
            delete: (id) =>
25
                this.delete({
25
                this.delete({
26
                    endpoint: "agreements/" + id,
26
                    endpoint: "agreements/" + id,
27
                    headers: this.getDefaultJSONPayloadHeader(),
28
                }),
27
                }),
29
            create: (agreement) =>
28
            create: (agreement) =>
30
                this.post({
29
                this.post({
31
                    endpoint: "agreements",
30
                    endpoint: "agreements",
32
                    body: agreement,
31
                    body: agreement,
33
                    headers: this.getDefaultJSONPayloadHeader(),
34
                }),
32
                }),
35
            update: (agreement, id) =>
33
            update: (agreement, id) =>
36
                this.put({
34
                this.put({
37
                    endpoint: "agreements/" + id,
35
                    endpoint: "agreements/" + id,
38
                    body: agreement,
36
                    body: agreement,
39
                    headers: this.getDefaultJSONPayloadHeader(),
40
                }),
37
                }),
41
            //count: () => this.count("agreements"), //TODO: Implement count method
38
            //count: () => this.count("agreements"), //TODO: Implement count method
42
        };
39
        };
43
    }
40
    }
44
}
41
}
45
42
46
export default ERMAPIClient;
43
export default ERMAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-7 / +4 lines)
Lines 1-12 Link Here
1
class HttpClient {
1
class HttpClient {
2
    constructor(options = {}) {
2
    constructor(options = {}) {
3
        this._baseURL = options.baseURL || "";
3
        this._baseURL = options.baseURL || "";
4
        this._headers = options.headers || {
5
            "Content-Type": "application/json;charset=utf-8",
6
        };
4
    }
7
    }
5
8
6
    async _fetchJSON(endpoint, headers = {}, options = {}) {
9
    async _fetchJSON(endpoint, headers = {}, options = {}) {
7
        const res = await fetch(this._baseURL + endpoint, {
10
        const res = await fetch(this._baseURL + endpoint, {
8
            ...options,
11
            ...options,
9
            headers: headers,
12
            headers: { ...this._headers, ...headers },
10
        });
13
        });
11
14
12
        if (!res.ok) throw new Error(res.statusText);
15
        if (!res.ok) throw new Error(res.statusText);
Lines 18-24 class HttpClient { Link Here
18
    }
21
    }
19
22
20
    get(params = {}) {
23
    get(params = {}) {
21
        console.log(params);
22
        return this._fetchJSON(params.endpoint, params.headers, {
24
        return this._fetchJSON(params.endpoint, params.headers, {
23
            ...params.options,
25
            ...params.options,
24
            method: "GET",
26
            method: "GET",
Lines 50-59 class HttpClient { Link Here
50
    }
52
    }
51
53
52
    //TODO: Implement count method
54
    //TODO: Implement count method
53
54
    getDefaultJSONPayloadHeader() {
55
        return { "Content-Type": "application/json;charset=utf-8" };
56
    }
57
}
55
}
58
56
59
export default HttpClient;
57
export default HttpClient;
60
- 

Return to bug 32939