Skip to content

Commit

Permalink
Merge pull request #411 from Mause/inspections
Browse files Browse the repository at this point in the history
Inspections
  • Loading branch information
Mause authored Oct 2, 2023
2 parents ccca48f + 98972ce commit fae50a9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
6 changes: 3 additions & 3 deletions api/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { GoogleSpreadsheet, GoogleSpreadsheetCell } from 'google-spreadsheet';
import _ from 'lodash';
import { DataResponse, Property, StatusMapping } from '../src/types';
import { augment } from '../support';
import { parseDate } from 'chrono-node';
import { uk } from 'chrono-node';

async function getProperties(): Promise<{
export async function getProperties(): Promise<{
rows: Partial<Property>[];
statusMapping: StatusMapping;
}> {
Expand All @@ -31,7 +31,7 @@ async function getProperties(): Promise<{
let value = row[header];

if (header == 'Available') {
value = value ? parseDate(value) : undefined;
value = value ? uk.parseDate(value) : undefined;
} else if (header == 'Beds') {
value = parseInt(value);
} else if (header == 'Interested') {
Expand Down
35 changes: 35 additions & 0 deletions api/inspections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { VercelRequest, VercelResponse } from '@vercel/node';
import { uk } from 'chrono-node';
import { getProperties } from './data';
import { augment } from '../support';

export default async function (
request: VercelRequest,
response: VercelResponse
) {
const { rows, statusMapping } = await getProperties();

const today = rows
.filter((prop) => prop['Viewed?'])
.map((prop) => {
const viewed = uk.parseDate(prop['Viewed?']!);
return { ...prop, today: isToday(viewed) };
})
.filter(({ today }) => today);

await augment(today);

response.json({ today, statusMapping });
}

function isToday(date: Date): boolean {
if (!date) {
return false;
}
const today = new Date();
return (
date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() == today.getFullYear()
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@vercel/node": "^1.12.1",
"axios": "^0.25.0",
"cheerio": "^1.0.0-rc.12",
"chrono-node": "^2.3.6",
"chrono-node": "^2.7.0",
"date-fns": "^2.28.0",
"google-spreadsheet": "^3.2.0",
"lodash": "^4.17.21",
Expand Down
7 changes: 7 additions & 0 deletions src/Inspections.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import useSWR from 'swr';

export default function Inspections() {
const { data } = useSWR('/api/inspections');

return <div>`${data}`</div>;
}
11 changes: 10 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import reportWebVitals from './reportWebVitals';
import { SWRConfig } from 'swr';
import * as Sentry from '@sentry/react';
import { Integrations } from '@sentry/tracing';
import Inspections from './Inspections';

Sentry.init({
dsn: process.env.REACT_APP_SENTRY_DSN,
Expand All @@ -16,10 +17,18 @@ Sentry.init({
tracesSampleRate: 1.0,
});

function AppWrapper() {
return window.location.pathname.includes('inspections') ? (
<Inspections />
) : (
<App />
);
}

ReactDOM.render(
<React.StrictMode>
<SWRConfig value={{}}>
<App />
<AppWrapper />
</SWRConfig>
</React.StrictMode>,
document.getElementById('root')
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4303,10 +4303,10 @@ chrome-trace-event@^1.0.2:
dependencies:
tslib "^1.9.0"

chrono-node@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/chrono-node/-/chrono-node-2.3.6.tgz#4fab8996f480f37e6ad646c8c9c7e40fe70f8d63"
integrity sha512-nWvpNZJXCfxHs5IfQEXqSYKiLFpz2PHB7SUdc8La2sjoG0S4ifDYLrpICrs/PsSCkZxN+AfVQq11Vd2ex5umjw==
chrono-node@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/chrono-node/-/chrono-node-2.7.0.tgz#2c25ed3d810ccd1fceabb630f70922af9600e45e"
integrity sha512-0s2vv89LmsbgoibV0AIVgNnGqlU8N5yCCVZXvc3mRCjnmlG/gJw1hCYOmNwjB+AIuwZQdKTXfwvsHDRTs6pwcg==
dependencies:
dayjs "^1.10.0"

Expand Down

1 comment on commit fae50a9

@vercel
Copy link

@vercel vercel bot commented on fae50a9 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.