Files
Martas 1294a177ae (#1) - WebPack bundling of JS and CSS (#1)
This work was done with Claude.

Added bundling of CSS & JS with WebPack. This also means minimization.

---------

Co-authored-by: Martin Slachta <martin.slachta@outlook.com>
Reviewed-on: #1
2026-06-12 10:57:23 +00:00

45 lines
1.3 KiB
JavaScript

export const RsvDataSource = {
create_rsv_resource(base_url, { nonce } = {}) {
function request(url, method, body) {
const headers = { 'Content-Type': 'application/json' };
if (nonce) headers['X-WP-Nonce'] = nonce;
else headers['X-WP-Nonce'] = ReservairServiceAPI.nonce;
return fetch(url, {
method,
credentials: 'same-origin',
headers,
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
}).then(r => {
if (!r.ok) throw new Error(`${method} ${url} failed: ${r.status}`);
return r.status === 204 ? null : r.json();
});
}
return {
base_url: base_url,
get_page(skip = 0, limit = 20, params = {}) {
const url = new URL(base_url);
url.searchParams.set('skip', skip);
url.searchParams.set('limit', limit);
for (const [k, v] of Object.entries(params)) {
url.searchParams.set(k, v);
}
return request(url, 'GET');
},
get(id) {
return request(`${base_url}/${id}`, 'GET');
},
post(data) {
return request(base_url, 'POST', data);
},
put(id, data) {
return request(`${base_url}/${id}`, 'PUT', data);
},
delete(id) {
return request(`${base_url}/${id}`, 'DELETE');
},
};
}
};