Inclui uso da API de marcas e modelos de carros

This commit is contained in:
Matheus Albino Brunhara
2022-08-29 02:06:36 -03:00
parent de0cf3b6f8
commit fa3fac82fb
5 changed files with 155 additions and 41 deletions

View File

@@ -1,32 +1,29 @@
import * as carsRoutes from "../api/cars";
interface getAllCarModelsReturn {
data?: {
id_model: string;
name: string;
}[];
interface CarObject {
codigo: string;
nome: string;
}
interface getAllCarBrandsReturn {
data?: CarObject[];
error?: {
errorMessage: string;
}
}
interface getAllCarModelsRes {
interface getAllCarBrandsRes {
status?: string;
message: string
data?: {
id_model: string;
name: string;
}[];
data?: CarObject[];
}
const getAllCarModels = async (): Promise<getAllCarModelsReturn> => {
const getAllCarBrands = async (): Promise<getAllCarBrandsReturn> => {
try {
let res: getAllCarModelsRes = await carsRoutes.list();
let res: getAllCarBrandsRes = await carsRoutes.listAllBrands();
if (res.status === "error") {
return {
@@ -42,10 +39,34 @@ const getAllCarModels = async (): Promise<getAllCarModelsReturn> => {
} catch (err) {
return {
error: {
errorMessage: "Por favor, autentique-se.",
errorMessage: "Por favor, tente novamente.",
},
};
}
};
export default { getAllCarModels };
const getCarModels = async (carBrandId: string): Promise<getAllCarBrandsReturn> => {
try {
let res: getAllCarBrandsRes = await carsRoutes.listCarModels(carBrandId);
if (res.status === "error") {
return {
error: {
errorMessage: res.message,
},
};
}
return {
data: res.data,
};
} catch (err) {
return {
error: {
errorMessage: "Por favor, tente novamente.",
},
};
}
};
export default { getAllCarBrands, getCarModels };