Cadastro de van agora faz requisições ao backend
This commit is contained in:
63
src/services/api/vans.ts
Normal file
63
src/services/api/vans.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import instance from "./api";
|
||||
|
||||
import vansRoutes from "../../constants/routes/vansRoutes";
|
||||
import { AxiosRequestHeaders } from "axios";
|
||||
import LocalStorage from "../../LocalStorage";
|
||||
|
||||
let token: string;
|
||||
let header: AxiosRequestHeaders;
|
||||
|
||||
function updateHeader() {
|
||||
token = LocalStorage.getToken();
|
||||
|
||||
header = {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getById(vanId: string) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.get(vansRoutes.getById.url + `/${vanId}`, {
|
||||
headers: header,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
interface CreateVanBody {
|
||||
plate: string;
|
||||
brand: string;
|
||||
model: string;
|
||||
seats_number: string;
|
||||
locator_name: string;
|
||||
locator_address: string;
|
||||
locator_complement: string;
|
||||
locator_city: string;
|
||||
locator_state: string;
|
||||
}
|
||||
|
||||
export async function create(CreateVanBody: CreateVanBody) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.post(vansRoutes.create.url, CreateVanBody);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
interface UpdateVanBody {
|
||||
brand?: string;
|
||||
model?: string;
|
||||
seats_number?: string;
|
||||
}
|
||||
|
||||
export async function update(vanData: UpdateVanBody) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.patch(vansRoutes.update.url, vanData, {
|
||||
headers: header,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
Reference in New Issue
Block a user