2023-11-25 19:32:43 -03:00
|
|
|
|
|
|
|
import { base, getToken } from './_config'
|
|
|
|
|
|
|
|
export async function getDispositivos(params) {
|
|
|
|
const query = !params ? '' : '?' + (new URLSearchParams(params).toString());
|
|
|
|
const res = await fetch(`${base}/dispositivos/${query}`, {
|
|
|
|
headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
|
|
|
|
})
|
|
|
|
if (!res.ok) throw await res.text()
|
|
|
|
return res.json()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function createDispositivo(data) {
|
|
|
|
const res = await fetch(`${base}/dispositivos/`, {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
|
|
|
|
})
|
|
|
|
if (!res.ok) throw await res.text()
|
|
|
|
return res.json()
|
|
|
|
}
|
|
|
|
|
2023-11-25 20:08:18 -03:00
|
|
|
export async function updateDispositivo({ id_dispositivo: id, ...data }) {
|
2023-11-25 19:32:43 -03:00
|
|
|
const res = await fetch(`${base}/dispositivos/${id}/`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
|
|
|
|
})
|
|
|
|
if (!res.ok) throw await res.text()
|
|
|
|
return res.json()
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteDispositivo(id) {
|
|
|
|
const res = await fetch(`${base}/dispositivos/${id}/`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" }
|
|
|
|
})
|
|
|
|
if (!res.ok) throw await res.text()
|
|
|
|
return res.text()
|
|
|
|
}
|