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

(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js (+2 lines)
Lines 13-18 import RecallAPIClient from "./recall-api-client.js"; Link Here
13
import SysprefAPIClient from "./system-preferences-api-client.js";
13
import SysprefAPIClient from "./system-preferences-api-client.js";
14
import TicketAPIClient from "./ticket-api-client.js";
14
import TicketAPIClient from "./ticket-api-client.js";
15
import AcquisitionAPIClient from "./acquisition-api-client.js";
15
import AcquisitionAPIClient from "./acquisition-api-client.js";
16
import DefaultAPIClient from "./default-api-client.js";
16
17
17
export const APIClient = {
18
export const APIClient = {
18
    article_request: new ArticleRequestAPIClient(HttpClient),
19
    article_request: new ArticleRequestAPIClient(HttpClient),
Lines 28-31 export const APIClient = { Link Here
28
    recall: new RecallAPIClient(HttpClient),
29
    recall: new RecallAPIClient(HttpClient),
29
    sysprefs: new SysprefAPIClient(HttpClient),
30
    sysprefs: new SysprefAPIClient(HttpClient),
30
    ticket: new TicketAPIClient(HttpClient),
31
    ticket: new TicketAPIClient(HttpClient),
32
    default: new DefaultAPIClient(HttpClient),
31
};
33
};
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/default-api-client.js (+19 lines)
Line 0 Link Here
1
export class DefaultAPIClient {
2
    constructor(HttpClient) {
3
        this.httpClient = new HttpClient({
4
            baseURL: "",
5
        });
6
    }
7
8
    get koha() {
9
        return {
10
            get: params => this.httpClient.get(params),
11
            getAll: params => this.httpClient.getAll(params),
12
            post: params => this.httpClient.post(params),
13
            put: params => this.httpClient.put(params),
14
            delete: params => this.httpClient.delete(params),
15
        };
16
    }
17
}
18
19
export default DefaultAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js (-6 / +40 lines)
Lines 105-110 class HttpClient { Link Here
105
        return res;
105
        return res;
106
    }
106
    }
107
107
108
    get(params = {}) {
109
        return this._fetchJSON(
110
            params.endpoint,
111
            params.headers,
112
            {
113
                ...params.options,
114
                method: "GET",
115
            },
116
            params.return_response ?? false,
117
            params.mark_submitting ?? false
118
        );
119
    }
120
121
    getAll(params = {}) {
122
        let url =
123
            params.endpoint +
124
            "?" +
125
            new URLSearchParams({
126
                _per_page: -1,
127
                ...(params.params && params.params),
128
                ...(params.query && { q: JSON.stringify(params.query) }),
129
            });
130
        return this._fetchJSON(
131
            url,
132
            params.headers,
133
            {
134
                ...params.options,
135
                method: "GET",
136
            },
137
            params.return_response ?? false,
138
            params.mark_submitting ?? false
139
        );
140
    }
141
108
    post(params = {}) {
142
    post(params = {}) {
109
        const body = params.body
143
        const body = params.body
110
            ? typeof params.body === "string"
144
            ? typeof params.body === "string"
Lines 121-128 class HttpClient { Link Here
121
                body,
155
                body,
122
                method: "POST",
156
                method: "POST",
123
            },
157
            },
124
            false,
158
            params.return_response ?? false,
125
            true
159
            params.mark_submitting ?? true
126
        );
160
        );
127
    }
161
    }
128
162
Lines 142-149 class HttpClient { Link Here
142
                body,
176
                body,
143
                method: "PUT",
177
                method: "PUT",
144
            },
178
            },
145
            false,
179
            params.return_response ?? false,
146
            true
180
            params.mark_submitting ?? true
147
        );
181
        );
148
    }
182
    }
149
183
Lines 158-165 class HttpClient { Link Here
158
                ...params.options,
192
                ...params.options,
159
                method: "DELETE",
193
                method: "DELETE",
160
            },
194
            },
161
            true,
195
            params.return_response ?? true,
162
            true
196
            params.mark_submitting ?? true
163
        );
197
        );
164
    }
198
    }
165
}
199
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-15 / +33 lines)
Lines 59-68 class HttpClient { Link Here
59
    }
59
    }
60
60
61
    get(params = {}) {
61
    get(params = {}) {
62
        return this._fetchJSON(params.endpoint, params.headers, {
62
        return this._fetchJSON(
63
            ...params.options,
63
            params.endpoint,
64
            method: "GET",
64
            params.headers,
65
        });
65
            {
66
                ...params.options,
67
                method: "GET",
68
            },
69
            params.return_response ?? false,
70
            params.mark_submitting ?? false
71
        );
66
    }
72
    }
67
73
68
    getAll(params = {}) {
74
    getAll(params = {}) {
Lines 74-83 class HttpClient { Link Here
74
                ...(params.params && params.params),
80
                ...(params.params && params.params),
75
                ...(params.query && { q: JSON.stringify(params.query) }),
81
                ...(params.query && { q: JSON.stringify(params.query) }),
76
            });
82
            });
77
        return this._fetchJSON(url, params.headers, {
83
        return this._fetchJSON(
78
            ...params.options,
84
            url,
79
            method: "GET",
85
            params.headers,
80
        });
86
            {
87
                ...params.options,
88
                method: "GET",
89
            },
90
            params.return_response ?? false,
91
            params.mark_submitting ?? false
92
        );
81
    }
93
    }
82
94
83
    post(params = {}) {
95
    post(params = {}) {
Lines 96-103 class HttpClient { Link Here
96
                body,
108
                body,
97
                method: "POST",
109
                method: "POST",
98
            },
110
            },
99
            false,
111
            params.return_response ?? false,
100
            true
112
            params.mark_submitting ?? true
101
        );
113
        );
102
    }
114
    }
103
115
Lines 117-124 class HttpClient { Link Here
117
                body,
129
                body,
118
                method: "PUT",
130
                method: "PUT",
119
            },
131
            },
120
            false,
132
            params.return_response ?? false,
121
            true
133
            params.mark_submitting ?? true
122
        );
134
        );
123
    }
135
    }
124
136
Lines 133-146 class HttpClient { Link Here
133
                ...params.options,
145
                ...params.options,
134
                method: "DELETE",
146
                method: "DELETE",
135
            },
147
            },
136
            true,
148
            params.return_response ?? true,
137
            true
149
            params.mark_submitting ?? true
138
        );
150
        );
139
    }
151
    }
140
152
141
    count(params = {}) {
153
    count(params = {}) {
142
        let res;
154
        let res;
143
        return this._fetchJSON(params.endpoint, params.headers, {}, 1).then(
155
        return this._fetchJSON(
156
            params.endpoint,
157
            params.headers,
158
            {},
159
            params.return_response ?? true,
160
            params.mark_submitting ?? false
161
        ).then(
144
            response => {
162
            response => {
145
                if (response) {
163
                if (response) {
146
                    return response.headers.get("X-Total-Count");
164
                    return response.headers.get("X-Total-Count");
(-)a/rspack.config.js (-1 / +34 lines)
Lines 161-164 module.exports = [ Link Here
161
            "datatables.net-buttons/js/buttons.colVis": "DataTable",
161
            "datatables.net-buttons/js/buttons.colVis": "DataTable",
162
        },
162
        },
163
    },
163
    },
164
    {
165
        entry: {
166
            "api-client.cjs":
167
                "./koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js",
168
        },
169
        output: {
170
            filename: "[name].js",
171
            path: path.resolve(__dirname, "t/cypress/plugins/dist/"),
172
            library: {
173
                type: "commonjs",
174
            },
175
            globalObject: "global",
176
        },
177
        target: "node",
178
        module: {
179
            rules: [
180
                {
181
                    test: /\.js$/,
182
                    loader: "builtin:swc-loader",
183
                    options: {
184
                        jsc: {
185
                            parser: {
186
                                syntax: "ecmascript",
187
                            },
188
                        },
189
                    },
190
                    exclude: [/node_modules/],
191
                    type: "javascript/auto",
192
                },
193
            ],
194
        },
195
        externals: [],
196
        plugins: [],
197
    },
164
];
198
];
165
- 

Return to bug 40173