/
home
/
infinitibizsol
/
.trash
/
controllers.3
/
File Upload :
llllll
Current File: /home/infinitibizsol/.trash/controllers.3/back4app.js
const fetch = require("node-fetch"); const getBack4MakeYear = async (req, res) => { const response = await fetch( "https://parseapi.back4app.com/classes/Car_Model_List?limit=200&keys=Year", { headers: { "X-Parse-Application-Id": "hlhoNKjOvEhqzcVAJ1lxjicJLZNVv36GdbboZj3Z", // This is the fake app's application id "X-Parse-Master-Key": "SNMJJF0CZZhTPhLDIqGhTlUNV9r60M2Z5spyWfXW", // This is the fake app's readonly master key }, } ); const data = await response.json(); // Here you have the data that you need return res.json(data.results); }; const getBack4MakeByYear = async (req, res) => { const where = encodeURIComponent( JSON.stringify({ Year: req.body.year, }) ); const response = await fetch( // `https://parseapi.back4app.com/classes/Carmodels_Car_Model_List?excludeKeys=Category&where=${where}`, `https://parseapi.back4app.com/classes/Carmodels_Car_Model_List?limit=500&keys=Make&where=${where}`, { headers: { "X-Parse-Application-Id": "JxfQ24gRftYvOP5eSamTlGxRlPj1APU1ahqzhMz5", // This is your app's application id "X-Parse-REST-API-Key": "QVd0BszmciBzA0n8dQRV8zJGs2QZi50CzoEuBIXQ", // This is your app's REST API key }, } ); const data = await response.json(); // Here you have the data that you need const makes = data.results.map((item) => item.Make); const uniqueMakes = [...new Set(makes)]; return res.json({ status: 200, data: uniqueMakes }); }; const getBack4ModelsByMake = async (req, res) => { const where = encodeURIComponent( JSON.stringify({ Make: req.body.make, Year: req.body.year, }) ); const response = await fetch( `https://parseapi.back4app.com/classes/Carmodels_Car_Model_List?limit=1000&keys=Model&where=${where}`, { headers: { "X-Parse-Application-Id": "JxfQ24gRftYvOP5eSamTlGxRlPj1APU1ahqzhMz5", // This is your app's application id "X-Parse-REST-API-Key": "QVd0BszmciBzA0n8dQRV8zJGs2QZi50CzoEuBIXQ", // This is your app's REST API key }, } ); const data = await response.json(); // Here you have the data that you need // return res.json(data.results); const models = data.results.map((item) => item.Model); const uniqueModels = [...new Set(models)]; return res.json({ status: 200, data: uniqueModels }); }; const getAllYears = async (req, res) => { const { year, bearer_token } = req.body; const url = `https://carapi.app/api/years`; const options = { method: "GET", }; try { const response = await fetch(url, options); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const yearsList = await response.json(); return res.json({ status: 200, message: "success", data: yearsList }); } catch (error) { console.error(error); } }; const getMakesByYear = async (req, res) => { const { year, bearer_token } = req.body; const url = `https://carapi.app/api/makes?year=${year}`; const options = { method: "GET", headers: { Accept: "application/json", Authorization: `Bearer ${bearer_token}`, }, }; try { const response = await fetch(url, options); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const body = await response.json(); // return res.json(body.data); const filteredMakes = body.data.map((item) => item.name); return res.json({ status: 200, message: "success", data: filteredMakes }); } catch (error) { console.error(error); } }; const getModelsByMake = async (req, res) => { const { year, make, bearer_token } = req.body; const url = `https://carapi.app/api/models?make=${make}&year=${year}`; const options = { method: "GET", headers: { Accept: "application/json", Authorization: `Bearer ${bearer_token}`, }, }; try { const response = await fetch(url, options); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const body = await response.json(); const filteredModels = body.data.map((item) => item.name); return res.json({ status: 200, message: "success", data: filteredModels, }); } catch (error) { console.error(error); } }; const vinDecoder = async (req, res) => { const { vin, bearer_token } = req.body; const url = `https://carapi.app/api/vin/${vin}`; const options = { method: "GET", headers: { Accept: "text/plain", "Content-Type": "application/json", Authorization: `Bearer ${bearer_token}`, }, }; try { const response = await fetch(url, options); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const body = await response.json(); return res.json({ status: 200, message: "success", data: body, }); } catch (error) { console.error(error); } }; module.exports = { getBack4MakeByYear, getBack4ModelsByMake, getBack4MakeYear, getMakesByYear, getModelsByMake, getAllYears, vinDecoder, };
Copyright ©2k19 -
Hexid
|
Tex7ure