2026-03-28 16:02:59 -05:00
|
|
|
const BASE = '/api'
|
|
|
|
|
|
|
|
|
|
async function request(path, options = {}) {
|
|
|
|
|
const res = await fetch(`${BASE}${path}`, {
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
...options,
|
|
|
|
|
})
|
|
|
|
|
const data = await res.json()
|
|
|
|
|
if (!res.ok) throw new Error(data.error || `Error ${res.status}`)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const api = {
|
|
|
|
|
guiones: {
|
2026-03-29 12:27:39 -05:00
|
|
|
listar: (params = {}) => request('/guiones?' + new URLSearchParams(params)),
|
|
|
|
|
listarTodos: (params = {}) => request('/guiones?' + new URLSearchParams({ ...params, todos: '1' })),
|
|
|
|
|
obtener: (id) => request(`/guiones/${id}`),
|
2026-03-28 16:02:59 -05:00
|
|
|
},
|
|
|
|
|
analizar: (body) => request('/analizar', { method: 'POST', body: JSON.stringify(body) }),
|
|
|
|
|
nichos: () => request('/nichos'),
|
|
|
|
|
clientes: () => request('/clientes'),
|
|
|
|
|
stats: () => request('/stats'),
|
|
|
|
|
}
|