Private
Public Access
25 lines
630 B
TypeScript
25 lines
630 B
TypeScript
import { API_URL } from '$lib/env';
|
|
import type { ActualizarRepuestoDto } from '../../../types';
|
|
import { getToken } from '../token';
|
|
|
|
export async function actualizarRepuesto(repuesto: ActualizarRepuestoDto) {
|
|
try {
|
|
const req = await fetch(`${API_URL}/repuestos/${repuesto.ID || 0}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${getToken()}`
|
|
},
|
|
body: JSON.stringify((({ ID, ...rest }) => rest)(repuesto))
|
|
});
|
|
|
|
if (req.ok) {
|
|
return 'Ok';
|
|
}
|
|
const data = await req.json();
|
|
return data.error;
|
|
} catch {
|
|
return 'no se puso alcanzar el servidor';
|
|
}
|
|
}
|