ls-deno/routes/user/[id].tsx

31 lines
743 B
TypeScript
Raw Permalink Normal View History

2022-10-21 03:06:37 -05:00
import { Handlers, PageProps } from "$fresh/server.ts";
import { getUser } from "@/db/mod.ts";
import { type Team, type User } from "@/types.ts";
interface UserPageProps {
user: User;
}
export const handler: Handlers<UserPageProps> = {
async GET(request, context) {
console.debug({ request, context });
const user = await getUser({ id: context.params.id });
if (!user) throw "unable to fetch from database";
return await context.render({ user });
},
};
export default function Team(
{ data: { user: { username, createdAt, displayName } } }: PageProps<
UserPageProps
>,
) {
return (
<>
<h1>
{(displayName || username).trim()} - joined {createdAt.toLocaleString()}
</h1>
</>
);
}