Skip to content

Commit fae50a9

Browse files
authored
Merge pull request #411 from Mause/inspections
Inspections
2 parents ccca48f + 98972ce commit fae50a9

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

api/data.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { GoogleSpreadsheet, GoogleSpreadsheetCell } from 'google-spreadsheet';
33
import _ from 'lodash';
44
import { DataResponse, Property, StatusMapping } from '../src/types';
55
import { augment } from '../support';
6-
import { parseDate } from 'chrono-node';
6+
import { uk } from 'chrono-node';
77

8-
async function getProperties(): Promise<{
8+
export async function getProperties(): Promise<{
99
rows: Partial<Property>[];
1010
statusMapping: StatusMapping;
1111
}> {
@@ -31,7 +31,7 @@ async function getProperties(): Promise<{
3131
let value = row[header];
3232

3333
if (header == 'Available') {
34-
value = value ? parseDate(value) : undefined;
34+
value = value ? uk.parseDate(value) : undefined;
3535
} else if (header == 'Beds') {
3636
value = parseInt(value);
3737
} else if (header == 'Interested') {

api/inspections.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { VercelRequest, VercelResponse } from '@vercel/node';
2+
import { uk } from 'chrono-node';
3+
import { getProperties } from './data';
4+
import { augment } from '../support';
5+
6+
export default async function (
7+
request: VercelRequest,
8+
response: VercelResponse
9+
) {
10+
const { rows, statusMapping } = await getProperties();
11+
12+
const today = rows
13+
.filter((prop) => prop['Viewed?'])
14+
.map((prop) => {
15+
const viewed = uk.parseDate(prop['Viewed?']!);
16+
return { ...prop, today: isToday(viewed) };
17+
})
18+
.filter(({ today }) => today);
19+
20+
await augment(today);
21+
22+
response.json({ today, statusMapping });
23+
}
24+
25+
function isToday(date: Date): boolean {
26+
if (!date) {
27+
return false;
28+
}
29+
const today = new Date();
30+
return (
31+
date.getDate() === today.getDate() &&
32+
date.getMonth() === today.getMonth() &&
33+
date.getFullYear() == today.getFullYear()
34+
);
35+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@vercel/node": "^1.12.1",
1313
"axios": "^0.25.0",
1414
"cheerio": "^1.0.0-rc.12",
15-
"chrono-node": "^2.3.6",
15+
"chrono-node": "^2.7.0",
1616
"date-fns": "^2.28.0",
1717
"google-spreadsheet": "^3.2.0",
1818
"lodash": "^4.17.21",

src/Inspections.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import useSWR from 'swr';
2+
3+
export default function Inspections() {
4+
const { data } = useSWR('/api/inspections');
5+
6+
return <div>`${data}`</div>;
7+
}

src/index.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import reportWebVitals from './reportWebVitals';
55
import { SWRConfig } from 'swr';
66
import * as Sentry from '@sentry/react';
77
import { Integrations } from '@sentry/tracing';
8+
import Inspections from './Inspections';
89

910
Sentry.init({
1011
dsn: process.env.REACT_APP_SENTRY_DSN,
@@ -16,10 +17,18 @@ Sentry.init({
1617
tracesSampleRate: 1.0,
1718
});
1819

20+
function AppWrapper() {
21+
return window.location.pathname.includes('inspections') ? (
22+
<Inspections />
23+
) : (
24+
<App />
25+
);
26+
}
27+
1928
ReactDOM.render(
2029
<React.StrictMode>
2130
<SWRConfig value={{}}>
22-
<App />
31+
<AppWrapper />
2332
</SWRConfig>
2433
</React.StrictMode>,
2534
document.getElementById('root')

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4303,10 +4303,10 @@ chrome-trace-event@^1.0.2:
43034303
dependencies:
43044304
tslib "^1.9.0"
43054305

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

0 commit comments

Comments
 (0)