Chart component. Update web utils.

This commit is contained in:
Mike Cao 2020-07-26 00:12:42 -07:00
parent f947c7770b
commit 590a70c2ff
6 changed files with 159 additions and 8 deletions

View file

@ -0,0 +1,10 @@
import { getPageviews } from 'lib/db';
export default async (req, res) => {
console.log(req.query);
const { id, start_at, end_at } = req.query;
const pageviews = await getPageviews(+id, new Date(+start_at), new Date(+end_at));
res.status(200).json({ pageviews });
};

View file

@ -2,6 +2,7 @@ import React from 'react';
import Link from 'next/link';
import cookies from 'next-cookies';
import Layout from 'components/Layout';
import Chart from 'components/Chart';
import { verifySecureToken } from 'lib/crypto';
export default function HomePage({ username }) {
@ -10,6 +11,13 @@ export default function HomePage({ username }) {
<h2>
You've successfully logged in as <b>{username}</b>.
</h2>
<div>
<Chart
websiteId={3}
startDate={Date.now() - 1000 * 60 * 60 * 24 * 7}
endDate={Date.now()}
/>
</div>
<Link href="/logout">
<a>Logout 🡒</a>
</Link>
@ -25,7 +33,7 @@ export async function getServerSideProps(context) {
return {
props: {
username: payload.username,
...payload,
},
};
} catch {