Subir todos los cambios recientes a la rama principal
This commit is contained in:
45
frontend-internal/src/lib/stores/api.ts
Normal file
45
frontend-internal/src/lib/stores/api.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const api = {
|
||||
async getClients() {
|
||||
const response = await fetch('/api/v1/clients');
|
||||
if (!response.ok) {
|
||||
throw new Error('Error fetching clients');
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
async createClient(client) {
|
||||
const response = await fetch('/api/v1/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(client),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Error creating client');
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
async updateClient(clientId, client) {
|
||||
const response = await fetch(`/api/v1/clients/${clientId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(client),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Error updating client');
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
|
||||
async deleteClient(clientId) {
|
||||
const response = await fetch(`/api/v1/clients/${clientId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Error deleting client');
|
||||
}
|
||||
return await response.json();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user