diff --git a/app/routes/inactivities.tsx b/app/routes/inactivities.tsx index 3b20d43..42d04ec 100644 --- a/app/routes/inactivities.tsx +++ b/app/routes/inactivities.tsx @@ -24,6 +24,7 @@ import { } from "@chakra-ui/react"; import { useLoaderData } from "@remix-run/react"; import { useState } from "react"; +import { type InactivityNotice } from "../../generated/prisma/client.js"; export async function loader({ context }: { context: RequestContext }) { const { current_user: currentUser } = context.data; @@ -57,18 +58,23 @@ export async function loader({ context }: { context: RequestContext }) { status: 403, }); - const today = new Date().toISOString().split("T").at(0); - const { results } = await context.env.D1.prepare( - "SELECT decisions, departments, end, hiatus, id, start, user FROM inactivity_notices WHERE start <= ?1 AND end >= date(?1, '-1 month') ORDER BY end;", - ) - .bind(today) - .all(); - - for (let i = 0; i < results.length; i++) { - results[i].decisions = JSON.parse(results[i].decisions as string); - results[i].departments = JSON.parse(results[i].departments as string); - results[i].user = JSON.parse(results[i].user as string); - } + let results = ( + await context.data.prisma.$queryRaw< + InactivityNotice[] + >`SELECT decisions, departments, end, hiatus, id, start, user FROM inactivity_notices WHERE start <= CURRENT_TIMESTAMP AND end >= date(CURRENT_TIMESTAMP, '-1 month') ORDER BY end;` + ).map((row) => { + return { + ...row, + decisions: JSON.parse(row.decisions as string) as { + [k: string]: boolean; + }, + departments: JSON.parse(row.departments as string) as string[], + user: JSON.parse(row.user as string) as { + id: string; + username: string; + }, + }; + }); return { can_delete: currentUser.permissions & (1 << 0), @@ -78,13 +84,7 @@ export async function loader({ context }: { context: RequestContext }) { ); return decisionValues.find((d) => d); - }) as unknown as { - decisions: { [k: string]: boolean }; - end: string; - id: string; - start: string; - user: { email?: string; id: string; username: string }; - }[], + }), }; } @@ -213,8 +213,8 @@ export default function () { {data.results.map((row) => ( - {row.user.username} - {row.user.id} + {row.user?.username} + {row.user?.id} {row.start} {row.end}