Move inactivities page to prisma
This commit is contained in:
+21
-21
@@ -24,6 +24,7 @@ import {
|
|||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useLoaderData } from "@remix-run/react";
|
import { useLoaderData } from "@remix-run/react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { type InactivityNotice } from "../../generated/prisma/client.js";
|
||||||
|
|
||||||
export async function loader({ context }: { context: RequestContext }) {
|
export async function loader({ context }: { context: RequestContext }) {
|
||||||
const { current_user: currentUser } = context.data;
|
const { current_user: currentUser } = context.data;
|
||||||
@@ -57,18 +58,23 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
status: 403,
|
status: 403,
|
||||||
});
|
});
|
||||||
|
|
||||||
const today = new Date().toISOString().split("T").at(0);
|
let results = (
|
||||||
const { results } = await context.env.D1.prepare(
|
await context.data.prisma.$queryRaw<
|
||||||
"SELECT decisions, departments, end, hiatus, id, start, user FROM inactivity_notices WHERE start <= ?1 AND end >= date(?1, '-1 month') ORDER BY end;",
|
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;`
|
||||||
.bind(today)
|
).map((row) => {
|
||||||
.all();
|
return {
|
||||||
|
...row,
|
||||||
for (let i = 0; i < results.length; i++) {
|
decisions: JSON.parse(row.decisions as string) as {
|
||||||
results[i].decisions = JSON.parse(results[i].decisions as string);
|
[k: string]: boolean;
|
||||||
results[i].departments = JSON.parse(results[i].departments as string);
|
},
|
||||||
results[i].user = JSON.parse(results[i].user as string);
|
departments: JSON.parse(row.departments as string) as string[],
|
||||||
}
|
user: JSON.parse(row.user as string) as {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
can_delete: currentUser.permissions & (1 << 0),
|
can_delete: currentUser.permissions & (1 << 0),
|
||||||
@@ -78,13 +84,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return decisionValues.find((d) => d);
|
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>
|
<Tbody>
|
||||||
{data.results.map((row) => (
|
{data.results.map((row) => (
|
||||||
<Tr key={row.id}>
|
<Tr key={row.id}>
|
||||||
<Td>{row.user.username}</Td>
|
<Td>{row.user?.username}</Td>
|
||||||
<Td>{row.user.id}</Td>
|
<Td>{row.user?.id}</Td>
|
||||||
<Td>{row.start}</Td>
|
<Td>{row.start}</Td>
|
||||||
<Td>{row.end}</Td>
|
<Td>{row.end}</Td>
|
||||||
<Td>
|
<Td>
|
||||||
|
|||||||
Reference in New Issue
Block a user