9a4c6863d1
- Add stages module with full CRUD API and admin overview island - Add mobility overview island (Liste, Kanban, Detail CRUD views) - Add contract PDF upload/download endpoints for mobilites - Add light/dark theme toggle in header - Add employeeOnly flag to hide entire modules from students (admin, students, stages) - Add read-only GET endpoints for modules/ues/ue-modules in notes module - Add [slug].tsx catch-all routes for direct URL navigation - Replace old mobility table with mobilites + stages schema (migration 0004) - Allow students to create mobilites and upload contracts - Redirect authenticated users from / to /apps catalog
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { FreshContext } from "$fresh/server.ts";
|
|
import { db } from "$root/databases/db.ts";
|
|
import { students } from "$root/databases/schema.ts";
|
|
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
|
import {
|
|
getPartialsConfig,
|
|
makePartials,
|
|
} from "$root/defaults/makePartials.tsx";
|
|
import { CasContent, State } from "$root/defaults/interfaces.ts";
|
|
import NotesView from "../(_islands)/NotesView.tsx";
|
|
|
|
async function Notes(
|
|
_request: Request,
|
|
context: FreshContext<State>,
|
|
) {
|
|
const session = (context.state as unknown as { session: CasContent }).session;
|
|
|
|
let numEtud: number | null = null;
|
|
try {
|
|
if (session.eduPersonPrimaryAffiliation === "student") {
|
|
// Students: uid is "<letter>21212006" in AMU CAS — strip non-digit prefix
|
|
const etudId = parseInt(session.uid.replace(/^\D+/, ""), 10);
|
|
if (!isNaN(etudId)) {
|
|
const student = await db
|
|
.select()
|
|
.from(students)
|
|
.where(eq(students.numEtud, etudId))
|
|
.then((rows) => rows[0] ?? null);
|
|
numEtud = student?.numEtud ?? null;
|
|
}
|
|
} else {
|
|
// Employees: look up by nom/prenom
|
|
const student = await db
|
|
.select()
|
|
.from(students)
|
|
.where(
|
|
and(
|
|
eq(students.nom, session.sn),
|
|
eq(students.prenom, session.givenName),
|
|
),
|
|
)
|
|
.then((rows) => rows[0] ?? null);
|
|
numEtud = student?.numEtud ?? null;
|
|
}
|
|
} catch {
|
|
// DB lookup failed — island will show fallback message
|
|
}
|
|
|
|
return (
|
|
<NotesView
|
|
numEtud={numEtud}
|
|
prenom={session.givenName || session.displayName}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export { Notes as Page };
|
|
export const config = getPartialsConfig();
|
|
export default makePartials(Notes);
|