diff --git a/src/app/utils/airtable.ts b/src/app/utils/airtable.ts index b146a69..6f8c543 100644 --- a/src/app/utils/airtable.ts +++ b/src/app/utils/airtable.ts @@ -1,7 +1,5 @@ -export const conciergeBase = 'app0ha03ugcl45qM1' - export const fromAirtable = async (base: string, table: string, id: string) => { - const d = await fetch(`https://drivly.airtable.do/${base}/${table}/${id}`, { + const d = await fetch(`https://airtable.vin/${base}/${table}/${id}`, { headers: { Authorization: `Bearer ${process.env.VIN_UNIVERSE_KEY}`, }, @@ -13,7 +11,7 @@ export const fromAirtable = async (base: string, table: string, id: string) => { } export const searchAirtable = async (base: string, table: string, query: string) => { - const d = await fetch(`https://drivly.airtable.do/${base}/${table}?filterByFormula=${query}`, { + const d = await fetch(`https://airtable.vin/${base}/${table}?filterByFormula=${query}`, { headers: { Authorization: `Bearer ${process.env.VIN_UNIVERSE_KEY}` }, }) diff --git a/src/app/utils/getATVehicleById.ts b/src/app/utils/getATVehicleById.ts index 80f049b..590aa35 100644 --- a/src/app/utils/getATVehicleById.ts +++ b/src/app/utils/getATVehicleById.ts @@ -1,10 +1,10 @@ -import 'server-only' import { formatDigits } from '@drivly/ui' -import { conciergeBase, fromAirtable } from './airtable' +import 'server-only' +import { fromAirtable } from './airtable' import { VehicleDetailProps } from './getVehicleDetails' export async function getATVehicleById(id: string) { - const data = await fromAirtable(conciergeBase, 'Vehicles', `rec${id}`) + const data = await fromAirtable('CRM', 'Vehicles', `rec${id}`) const price = findAirtablePrice(data) return { diff --git a/src/app/utils/getVehicleDetails.ts b/src/app/utils/getVehicleDetails.ts index 1b3290a..19cade4 100644 --- a/src/app/utils/getVehicleDetails.ts +++ b/src/app/utils/getVehicleDetails.ts @@ -1,9 +1,9 @@ 'use server' -import z from 'zod' -import getListing from '@drivly/ui/dist/lib/getListing' import { formatDigits } from '@drivly/ui' -import { conciergeBase, searchAirtable } from './airtable' +import getListing from '@drivly/ui/dist/lib/getListing' +import z from 'zod' +import { searchAirtable } from './airtable' const vehicleSchema = z.object({ year: z.string(), @@ -49,10 +49,10 @@ export async function getVehicleDetails(id: string) { } export const fetchPrice = async (id: string) => { - const data = await searchAirtable(conciergeBase, 'Vehicles', `AND({VIN}='${id}')`) - if (!data?.records?.length) return null - - const highestPricedRecord = findHighestPricedRecord(data?.records) + const data = await searchAirtable('CRM', 'Vehicles', `AND({VIN}='${id}')`) + if (data?.length === 0) return null + + const highestPricedRecord = findHighestPricedRecord(data) const salesPrice = highestPricedRecord?.salesPrice || '' const buyNow = highestPricedRecord?.buyNow || '' const retailPrice = highestPricedRecord?.retailPrice || ''