diff --git a/src/app/utils/airtable.ts b/src/app/utils/airtable.ts index 40a7bcc..b0717fc 100644 --- a/src/app/utils/airtable.ts +++ b/src/app/utils/airtable.ts @@ -13,7 +13,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://airtable.vin/${base}/${table}?filterByFormula=${query}`, { + const d = await fetch(`https://airtable.vin/${base}/${table}?${query}`, { headers: { Authorization: `Bearer ${process.env.VIN_UNIVERSE_KEY}` }, }) diff --git a/src/app/utils/getVehicleDetails.ts b/src/app/utils/getVehicleDetails.ts index 0653745..b9e2ca7 100644 --- a/src/app/utils/getVehicleDetails.ts +++ b/src/app/utils/getVehicleDetails.ts @@ -3,7 +3,7 @@ import z from 'zod' import getListing from '@drivly/ui/dist/lib/getListing' import { formatDigits } from '@drivly/ui' -import { conciergeBase, searchAirtable } from './airtable' +import { searchAirtable } from './airtable' const vehicleSchema = z.object({ year: z.string(), @@ -49,7 +49,7 @@ export async function getVehicleDetails(id: string) { } export const fetchPrice = async (id: string) => { - const data = await searchAirtable('CRM', 'Vehicles', `AND({VIN}='${id}')`) + const data = await searchAirtable('CRM', 'Vehicles', `vin='${id}`) if (!data?.length) return null const highestPricedRecord = findHighestPricedRecord(data) diff --git a/src/utils/slackMsg.ts b/src/utils/slackMsg.ts index 3a05647..f97bf7b 100644 --- a/src/utils/slackMsg.ts +++ b/src/utils/slackMsg.ts @@ -26,7 +26,7 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'section', text: { type: 'mrkdwn', - text: `*CREDIT APP* REQUEST ${date} :rocket:\n* ${data.primary.firstName} ${data.primary.lastName} | ${data.primary.email}*`, + text: `*${data.primary.firstName} ${data.primary.lastName}* | ${date} :moneybag:\n* ${data.primary.email} | ${date}*`, }, }) blocks.push({ @@ -40,20 +40,22 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { data.primary?.middleName || '' } ${data.primary.lastName}\n*Phone:* ${data.primary.phone} ${ data.primary.phoneType - }\n*Email:* ${data.primary.email}\n*Date of Birth:* ${data.primary.dateOfBirth}\n*SSN:* ${ - data.primary.ssn - }`, + }\n*Email:* ${data.primary.email}\n*Date of Birth:* ${ + data.primary.dateOfBirth + }\n*SSN:* ${data.primary.ssn}`, }, }) blocks.push({ type: 'section', text: { type: 'mrkdwn', - text: `*Residence*\n*Address:* ${data.primary.addressLine1} \n*City:* ${ - data.primary.city - }\n*State:* ${data.primary.state}\n*Zip Code:* ${ - data.primary.zipCode - }\n*Time at address:* ${data.primary.addressYears} yrs ${ + text: `*Residence*\n*Address:* ${ + data.primary.addressLine1 + } \n*City:* ${data.primary.city}\n*State:* ${ + data.primary.state + }\n*Zip Code:* ${data.primary.zipCode}\n*Time at address:* ${ + data.primary.addressYears + } yrs ${ data.primary.addressMonths ? data.primary.addressMonths + 'mo' : '' }\n*Monthly payment/rent:* ${data.primary.rentMortgagePaymentAmount}`, }, @@ -63,13 +65,19 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'section', text: { type: 'mrkdwn', - text: `*Previous Residence*\n*Address:* ${data.primary.prevAddressLine1} \n*City:* ${ - data.primary.prevCity - }\n*State:* ${data.primary.prevState}\n*Zip Code:* ${ - data.primary.zipCode - }\n*Time at address:* ${data.primary.prevAddressYears} yrs ${ - data.primary.prevAddressMonths ? data.primary.prevAddressMonths + 'mo' : '' - }\n*Monthly payment/rent:* ${data.primary.prevRentMortgagePaymentAmount}`, + text: `*Previous Residence*\n*Address:* ${ + data.primary.prevAddressLine1 + } \n*City:* ${data.primary.prevCity}\n*State:* ${ + data.primary.prevState + }\n*Zip Code:* ${data.primary.zipCode}\n*Time at address:* ${ + data.primary.prevAddressYears + } yrs ${ + data.primary.prevAddressMonths + ? data.primary.prevAddressMonths + 'mo' + : '' + }\n*Monthly payment/rent:* ${ + data.primary.prevRentMortgagePaymentAmount + }`, }, }) blocks.push({ @@ -85,12 +93,14 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'mrkdwn', text: `*Employment History*\n*Employer name:* ${ data.primary.employerName - }\n*Employment Status:* ${data.primary.employmentStatusCode}\n*Employer phone:* ${ - data.primary?.employerPhone - }\n*Occupation:* ${data.primary?.employmentTitle}\n*Time on job:* ${ - data.primary?.timeOnJobYears - } yrs ${ - data.primary?.timeOnJobMonths ? data.primary?.timeOnJobMonths + 'mo' : '' + }\n*Employment Status:* ${ + data.primary.employmentStatusCode + }\n*Employer phone:* ${data.primary?.employerPhone}\n*Occupation:* ${ + data.primary?.employmentTitle + }\n*Time on job:* ${data.primary?.timeOnJobYears} yrs ${ + data.primary?.timeOnJobMonths + ? data.primary?.timeOnJobMonths + 'mo' + : '' }\n*Monthly income:* ${data.primary?.incomeAmount}`, }, }) @@ -101,10 +111,14 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'mrkdwn', text: `*Previous Employment*\n*Employer name:* ${ data.primary?.previousEmployerName - }\n*Employer phone:* ${data.primary?.prevEmployerPhone}\n*Occupation:* ${ + }\n*Employer phone:* ${ + data.primary?.prevEmployerPhone + }\n*Occupation:* ${ data.primary?.prevEmploymentTitle }\n*Time on job:* ${data.primary?.prevTimeOnJobYears} yrs ${ - data.primary?.prevTimeOnJobMonths ? data.primary?.prevTimeOnJobMonths + 'mo' : '' + data.primary?.prevTimeOnJobMonths + ? data.primary?.prevTimeOnJobMonths + 'mo' + : '' }\n*Monthly income:* ${data.primary?.prevIncomeAmount}`, }, }) @@ -130,13 +144,19 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'section', text: { type: 'mrkdwn', - text: `*Residence*\n*Address:* ${data.secondary.addressLine1} \n*City:* ${ - data.secondary.city - }\n*State:* ${data.secondary.state}*Zip Code:* ${ - data.secondary.zipCode - }\n*Time at address:* ${data.secondary.addressYears} yrs ${ - data.secondary.addressMonths ? data.secondary.addressMonths + 'mo' : '' - }\n*Monthly payment/rent:* ${data.secondary.rentMortgagePaymentAmount}`, + text: `*Residence*\n*Address:* ${ + data.secondary.addressLine1 + } \n*City:* ${data.secondary.city}\n*State:* ${ + data.secondary.state + }*Zip Code:* ${data.secondary.zipCode}\n*Time at address:* ${ + data.secondary.addressYears + } yrs ${ + data.secondary.addressMonths + ? data.secondary.addressMonths + 'mo' + : '' + }\n*Monthly payment/rent:* ${ + data.secondary.rentMortgagePaymentAmount + }`, }, }) Number(data.secondary.addressYears) < 2 && @@ -144,13 +164,19 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'section', text: { type: 'mrkdwn', - text: `*Previous Residence*\n*Address:* ${data.secondary.prevAddressLine1} \n*City:* ${ - data.secondary.prevCity - }\n*State:* ${data.secondary.prevState}\n*Zip Code:* ${ - data.secondary.prevZipCode - }\n*Time at address:* ${data.secondary.prevAddressYears} yrs ${ - data.secondary.prevAddressMonths ? data.secondary.prevAddressMonths + 'mo' : '' - }\n*Monthly payment/rent:* ${data.secondary.prevRentMortgagePaymentAmount}`, + text: `*Previous Residence*\n*Address:* ${ + data.secondary.prevAddressLine1 + } \n*City:* ${data.secondary.prevCity}\n*State:* ${ + data.secondary.prevState + }\n*Zip Code:* ${data.secondary.prevZipCode}\n*Time at address:* ${ + data.secondary.prevAddressYears + } yrs ${ + data.secondary.prevAddressMonths + ? data.secondary.prevAddressMonths + 'mo' + : '' + }\n*Monthly payment/rent:* ${ + data.secondary.prevRentMortgagePaymentAmount + }`, }, }) blocks.push({ @@ -166,12 +192,16 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'mrkdwn', text: `*Employment History*\n*Employer name:* ${ data?.secondary?.employerName - }\n*Employment Status:* ${data?.secondary?.employmentStatusCode}\n*Employer phone:* ${ + }\n*Employment Status:* ${ + data?.secondary?.employmentStatusCode + }\n*Employer phone:* ${ data?.secondary?.employerPhone - }\n*Occupation:* ${data?.secondary?.employmentTitle}\n*Time on job:* ${ - data?.secondary?.timeOnJobYears - } yrs ${ - data?.secondary?.timeOnJobMonths ? data?.secondary?.timeOnJobMonths + 'mo' : '' + }\n*Occupation:* ${ + data?.secondary?.employmentTitle + }\n*Time on job:* ${data?.secondary?.timeOnJobYears} yrs ${ + data?.secondary?.timeOnJobMonths + ? data?.secondary?.timeOnJobMonths + 'mo' + : '' }\n*Monthly income:* ${data?.secondary?.incomeAmount}`, }, }) @@ -182,10 +212,14 @@ export async function slackMsgRequest({ url, data }: SlackMsgRequest) { type: 'mrkdwn', text: `*Previous Employment*\n*Employer name:* ${ data?.secondary?.previousEmployerName - }\n*Employer phone:* ${data?.secondary?.prevEmployerPhone}\n*Occupation:* ${ + }\n*Employer phone:* ${ + data?.secondary?.prevEmployerPhone + }\n*Occupation:* ${ data?.secondary?.prevEmploymentTitle }\n*Time on job:* ${data?.secondary?.prevTimeOnJobYears} yrs ${ - data?.secondary?.prevTimeOnJobMonths ? data?.secondary?.prevTimeOnJobMonths + 'mo' : '' + data?.secondary?.prevTimeOnJobMonths + ? data?.secondary?.prevTimeOnJobMonths + 'mo' + : '' }\n*Monthly income:* ${data?.secondary?.prevIncomeAmount}`, }, })