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