Move inactivities page to prisma
This commit is contained in:
+21
-21
@@ -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 () {
|
||||
<Tbody>
|
||||
{data.results.map((row) => (
|
||||
<Tr key={row.id}>
|
||||
<Td>{row.user.username}</Td>
|
||||
<Td>{row.user.id}</Td>
|
||||
<Td>{row.user?.username}</Td>
|
||||
<Td>{row.user?.id}</Td>
|
||||
<Td>{row.start}</Td>
|
||||
<Td>{row.end}</Td>
|
||||
<Td>
|
||||
|
||||
Reference in New Issue
Block a user