chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+50
@@ -0,0 +1,50 @@
|
||||
const API_BASE = '/api';
|
||||
|
||||
async function request(path, options = {}) {
|
||||
const token = localStorage.getItem('delamain_token');
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||
const resp = await fetch(`${API_BASE}${path}`, {
|
||||
...options,
|
||||
headers,
|
||||
});
|
||||
if (!resp.ok && resp.status !== 400 && resp.status !== 403 && resp.status !== 404) {
|
||||
const body = await resp.json().catch(() => ({}));
|
||||
throw new Error(body.error || `Request failed: ${resp.status}`);
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
const api = {
|
||||
request,
|
||||
|
||||
login: (username, password) =>
|
||||
request('/login', { method: 'POST', body: JSON.stringify({ username, password }) }),
|
||||
|
||||
createUser: (username, password) =>
|
||||
request('/users', { method: 'POST', body: JSON.stringify({ username, password }) }),
|
||||
|
||||
createTrip: (tripData) =>
|
||||
request('/trips', { method: 'POST', body: JSON.stringify(tripData) }),
|
||||
|
||||
getTrip: (tripId) => request(`/trips/${tripId}`),
|
||||
|
||||
getAllTrips: () => request('/trips'),
|
||||
|
||||
getVersions: (tripId) => request(`/trips/${tripId}/versions`),
|
||||
|
||||
createPackage: (tripId) =>
|
||||
request('/packages', { method: 'POST', body: JSON.stringify({ trip_id: tripId }) }),
|
||||
|
||||
|
||||
|
||||
estimate: (fromX, fromY, toX, toY, cls) =>
|
||||
request('/estimate', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ from_x: fromX, from_y: fromY, to_x: toX, to_y: toY, class: cls }),
|
||||
}),
|
||||
|
||||
bookRide: (payload) => request('/trips', { method: 'POST', body: JSON.stringify(payload) }),
|
||||
|
||||
|
||||
};
|
||||
Reference in new issue
Block a user