Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 401160aa30 | |||
| 9368e68622 | |||
| e2d22ff4b3 | |||
| ad64fd0a99 | |||
| f71128a7f3 | |||
| 720a380be8 | |||
| 6c602cb10a | |||
| bb09c1cce5 | |||
| f162fcaadc | |||
| 2c5e4ebf11 | |||
| 757e364af0 |
@@ -0,0 +1,4 @@
|
|||||||
|
node_modules
|
||||||
|
.git
|
||||||
|
coverage
|
||||||
|
.env
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
FROM denoland/deno:alpine
|
FROM denoland/deno:alpine
|
||||||
|
|
||||||
|
RUN apk add --no-cache nodejs npm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json ./
|
||||||
|
RUN npm install --omit=dev
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN deno cache main.ts --allow-import
|
RUN deno cache main.ts --allow-import
|
||||||
RUN deno task build
|
RUN deno task build
|
||||||
|
|||||||
+3
-1
@@ -16,7 +16,9 @@ services:
|
|||||||
|
|
||||||
migrate:
|
migrate:
|
||||||
image: registry.docker.polytech.djalim.fr/polympr:latest
|
image: registry.docker.polytech.djalim.fr/polympr:latest
|
||||||
command: node_modules/.bin/drizzle-kit migrate
|
working_dir: /app
|
||||||
|
restart: "no"
|
||||||
|
command: ["node", "node_modules/.bin/drizzle-kit", "migrate"]
|
||||||
env_file: .env
|
env_file: .env
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ INSERT INTO "permissions" ("id", "nom") VALUES
|
|||||||
('module_read', 'Consulter les modules et enseignements'),
|
('module_read', 'Consulter les modules et enseignements'),
|
||||||
('module_write', 'Gérer les modules et enseignements'),
|
('module_write', 'Gérer les modules et enseignements'),
|
||||||
('user_read', 'Consulter les utilisateurs et leurs rôles'),
|
('user_read', 'Consulter les utilisateurs et leurs rôles'),
|
||||||
('user_write', 'Gérer les utilisateurs et leurs rôles');
|
('user_write', 'Gérer les utilisateurs et leurs rôles'),
|
||||||
|
('role_write', 'Gérer les rôles et leurs permissions');
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ INSERT INTO "permissions" ("id", "nom") VALUES
|
|||||||
('module_read', 'Consulter les modules et enseignements'),
|
('module_read', 'Consulter les modules et enseignements'),
|
||||||
('module_write', 'Gérer les modules et enseignements'),
|
('module_write', 'Gérer les modules et enseignements'),
|
||||||
('user_read', 'Consulter les utilisateurs et leurs rôles'),
|
('user_read', 'Consulter les utilisateurs et leurs rôles'),
|
||||||
('user_write', 'Gérer les utilisateurs et leurs rôles')
|
('user_write', 'Gérer les utilisateurs et leurs rôles'),
|
||||||
|
('role_write', 'Gérer les rôles et leurs permissions')
|
||||||
ON CONFLICT ("id") DO UPDATE SET "nom" = EXCLUDED."nom";
|
ON CONFLICT ("id") DO UPDATE SET "nom" = EXCLUDED."nom";
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
import { db } from "$root/databases/db.ts";
|
||||||
|
import {
|
||||||
|
enseignements,
|
||||||
|
rolePermissions,
|
||||||
|
users,
|
||||||
|
} from "$root/databases/schema.ts";
|
||||||
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
|
type RuleFn = (
|
||||||
|
req: Request,
|
||||||
|
ctx: FreshContext<AuthenticatedState>,
|
||||||
|
) => Promise<boolean> | boolean;
|
||||||
|
|
||||||
|
async function hasPermission(
|
||||||
|
uid: string,
|
||||||
|
permission: string,
|
||||||
|
): Promise<boolean> {
|
||||||
|
const [user] = await db.select().from(users).where(eq(users.id, uid));
|
||||||
|
if (!user || user.idRole === null) return false;
|
||||||
|
|
||||||
|
const [rp] = await db.select().from(rolePermissions).where(
|
||||||
|
and(
|
||||||
|
eq(rolePermissions.idRole, user.idRole!),
|
||||||
|
eq(rolePermissions.idPermission, permission),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return !!rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNumEtud(uid: string): number {
|
||||||
|
return parseInt(uid.slice(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
student_read: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "student_read"),
|
||||||
|
student_write: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "student_write"),
|
||||||
|
note_read: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "note_read"),
|
||||||
|
note_write: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "note_write"),
|
||||||
|
module_read: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "module_read"),
|
||||||
|
module_write: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "module_write"),
|
||||||
|
user_read: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "user_read"),
|
||||||
|
user_write: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "user_write"),
|
||||||
|
role_write: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
hasPermission(ctx.state.session.uid, "role_write"),
|
||||||
|
|
||||||
|
// Contextual rules — student accessing their own data
|
||||||
|
own_student: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
parseNumEtud(ctx.state.session.uid) === Number(ctx.params.numEtud),
|
||||||
|
own_note: (_req: Request, ctx: FreshContext<AuthenticatedState>) =>
|
||||||
|
parseNumEtud(ctx.state.session.uid) === Number(ctx.params.numEtud),
|
||||||
|
|
||||||
|
// Contextual rule — teacher accessing notes for a module they teach
|
||||||
|
own_teaching_note: async (
|
||||||
|
_req: Request,
|
||||||
|
ctx: FreshContext<AuthenticatedState>,
|
||||||
|
) => {
|
||||||
|
const [row] = await db.select().from(enseignements).where(
|
||||||
|
and(
|
||||||
|
eq(enseignements.idProf, ctx.state.session.uid),
|
||||||
|
eq(enseignements.idModule, ctx.params.idModule),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return !!row;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RuleName = keyof typeof rules;
|
||||||
|
|
||||||
|
type HandlerFn = (
|
||||||
|
req: Request,
|
||||||
|
ctx: FreshContext<AuthenticatedState>,
|
||||||
|
) => Promise<Response>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a route handler with permission checks.
|
||||||
|
* Access is granted if ANY of the provided rules passes (OR logic).
|
||||||
|
* Returns 403 if none pass.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
|
* GET: withRules(["note_read", "own_note"])(async (req, ctx) => {
|
||||||
|
* // ...
|
||||||
|
* }),
|
||||||
|
* };
|
||||||
|
*/
|
||||||
|
export function withRules(ruleNames: RuleName[]) {
|
||||||
|
return (handler: HandlerFn): HandlerFn => {
|
||||||
|
return async (req, ctx) => {
|
||||||
|
const results = await Promise.all(
|
||||||
|
ruleNames.map((name) => rules[name](req, ctx)),
|
||||||
|
);
|
||||||
|
if (!results.some(Boolean)) {
|
||||||
|
return new Response(null, { status: 403 });
|
||||||
|
}
|
||||||
|
return handler(req, ctx);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -34,7 +34,9 @@ import * as $_apps_notes_api_ue_modules from "./routes/(apps)/notes/api/ue-modul
|
|||||||
import * as $_apps_notes_api_ue_modules_idModule_idUE_idPromo_ from "./routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts";
|
import * as $_apps_notes_api_ue_modules_idModule_idUE_idPromo_ from "./routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts";
|
||||||
import * as $_apps_notes_api_ues from "./routes/(apps)/notes/api/ues.ts";
|
import * as $_apps_notes_api_ues from "./routes/(apps)/notes/api/ues.ts";
|
||||||
import * as $_apps_notes_api_ues_idUE_ from "./routes/(apps)/notes/api/ues/[idUE].ts";
|
import * as $_apps_notes_api_ues_idUE_ from "./routes/(apps)/notes/api/ues/[idUE].ts";
|
||||||
|
import * as $_apps_notes_edition_numEtud_ from "./routes/(apps)/notes/edition/[numEtud].tsx";
|
||||||
import * as $_apps_notes_index from "./routes/(apps)/notes/index.tsx";
|
import * as $_apps_notes_index from "./routes/(apps)/notes/index.tsx";
|
||||||
|
import * as $_apps_notes_recap_numEtud_ from "./routes/(apps)/notes/recap/[numEtud].tsx";
|
||||||
import * as $_apps_notes_partials_admin_courses from "./routes/(apps)/notes/partials/(admin)/courses.tsx";
|
import * as $_apps_notes_partials_admin_courses from "./routes/(apps)/notes/partials/(admin)/courses.tsx";
|
||||||
import * as $_apps_notes_partials_admin_import from "./routes/(apps)/notes/partials/(admin)/import.tsx";
|
import * as $_apps_notes_partials_admin_import from "./routes/(apps)/notes/partials/(admin)/import.tsx";
|
||||||
import * as $_apps_notes_partials_admin_ues from "./routes/(apps)/notes/partials/(admin)/ues.tsx";
|
import * as $_apps_notes_partials_admin_ues from "./routes/(apps)/notes/partials/(admin)/ues.tsx";
|
||||||
@@ -74,6 +76,7 @@ import * as $_apps_mobility_islands_ImportFile from "./routes/(apps)/mobility/(_
|
|||||||
import * as $_apps_notes_islands_AdminConsultNotes from "./routes/(apps)/notes/(_islands)/AdminConsultNotes.tsx";
|
import * as $_apps_notes_islands_AdminConsultNotes from "./routes/(apps)/notes/(_islands)/AdminConsultNotes.tsx";
|
||||||
import * as $_apps_notes_islands_AdminUEs from "./routes/(apps)/notes/(_islands)/AdminUEs.tsx";
|
import * as $_apps_notes_islands_AdminUEs from "./routes/(apps)/notes/(_islands)/AdminUEs.tsx";
|
||||||
import * as $_apps_notes_islands_ImportNotes from "./routes/(apps)/notes/(_islands)/ImportNotes.tsx";
|
import * as $_apps_notes_islands_ImportNotes from "./routes/(apps)/notes/(_islands)/ImportNotes.tsx";
|
||||||
|
import * as $_apps_notes_islands_NoteRecap from "./routes/(apps)/notes/(_islands)/NoteRecap.tsx";
|
||||||
import * as $_apps_notes_islands_NotesView from "./routes/(apps)/notes/(_islands)/NotesView.tsx";
|
import * as $_apps_notes_islands_NotesView from "./routes/(apps)/notes/(_islands)/NotesView.tsx";
|
||||||
import * as $_apps_students_islands_AdminPromotions from "./routes/(apps)/students/(_islands)/AdminPromotions.tsx";
|
import * as $_apps_students_islands_AdminPromotions from "./routes/(apps)/students/(_islands)/AdminPromotions.tsx";
|
||||||
import * as $_apps_students_islands_ConsultStudents from "./routes/(apps)/students/(_islands)/ConsultStudents.tsx";
|
import * as $_apps_students_islands_ConsultStudents from "./routes/(apps)/students/(_islands)/ConsultStudents.tsx";
|
||||||
@@ -128,7 +131,10 @@ const manifest = {
|
|||||||
$_apps_notes_api_ue_modules_idModule_idUE_idPromo_,
|
$_apps_notes_api_ue_modules_idModule_idUE_idPromo_,
|
||||||
"./routes/(apps)/notes/api/ues.ts": $_apps_notes_api_ues,
|
"./routes/(apps)/notes/api/ues.ts": $_apps_notes_api_ues,
|
||||||
"./routes/(apps)/notes/api/ues/[idUE].ts": $_apps_notes_api_ues_idUE_,
|
"./routes/(apps)/notes/api/ues/[idUE].ts": $_apps_notes_api_ues_idUE_,
|
||||||
|
"./routes/(apps)/notes/edition/[numEtud].tsx":
|
||||||
|
$_apps_notes_edition_numEtud_,
|
||||||
"./routes/(apps)/notes/index.tsx": $_apps_notes_index,
|
"./routes/(apps)/notes/index.tsx": $_apps_notes_index,
|
||||||
|
"./routes/(apps)/notes/recap/[numEtud].tsx": $_apps_notes_recap_numEtud_,
|
||||||
"./routes/(apps)/notes/partials/(admin)/courses.tsx":
|
"./routes/(apps)/notes/partials/(admin)/courses.tsx":
|
||||||
$_apps_notes_partials_admin_courses,
|
$_apps_notes_partials_admin_courses,
|
||||||
"./routes/(apps)/notes/partials/(admin)/import.tsx":
|
"./routes/(apps)/notes/partials/(admin)/import.tsx":
|
||||||
@@ -193,6 +199,8 @@ const manifest = {
|
|||||||
$_apps_notes_islands_AdminUEs,
|
$_apps_notes_islands_AdminUEs,
|
||||||
"./routes/(apps)/notes/(_islands)/ImportNotes.tsx":
|
"./routes/(apps)/notes/(_islands)/ImportNotes.tsx":
|
||||||
$_apps_notes_islands_ImportNotes,
|
$_apps_notes_islands_ImportNotes,
|
||||||
|
"./routes/(apps)/notes/(_islands)/NoteRecap.tsx":
|
||||||
|
$_apps_notes_islands_NoteRecap,
|
||||||
"./routes/(apps)/notes/(_islands)/NotesView.tsx":
|
"./routes/(apps)/notes/(_islands)/NotesView.tsx":
|
||||||
$_apps_notes_islands_NotesView,
|
$_apps_notes_islands_NotesView,
|
||||||
"./routes/(apps)/students/(_islands)/AdminPromotions.tsx":
|
"./routes/(apps)/students/(_islands)/AdminPromotions.tsx":
|
||||||
|
|||||||
+1
-1
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^17.4.0",
|
"dotenv": "^17.4.0",
|
||||||
|
"drizzle-kit": "^0.31.10",
|
||||||
"drizzle-orm": "^0.45.2",
|
"drizzle-orm": "^0.45.2",
|
||||||
"pg": "^8.20.0"
|
"pg": "^8.20.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/pg": "^8.20.0",
|
"@types/pg": "^8.20.0",
|
||||||
"drizzle-kit": "^0.31.10",
|
|
||||||
"tsx": "^4.21.0"
|
"tsx": "^4.21.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,391 @@
|
|||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
type Student = {
|
||||||
|
numEtud: number;
|
||||||
|
nom: string;
|
||||||
|
prenom: string;
|
||||||
|
idPromo: string;
|
||||||
|
};
|
||||||
|
type UE = { id: number; nom: string };
|
||||||
|
type UEModule = {
|
||||||
|
idModule: string;
|
||||||
|
idUE: number;
|
||||||
|
idPromo: string;
|
||||||
|
coeff: number;
|
||||||
|
};
|
||||||
|
type Module = { id: string; nom: string };
|
||||||
|
type Note = { numEtud: number; idModule: string; note: number };
|
||||||
|
type Ajustement = { numEtud: number; idUE: number; valeur: number };
|
||||||
|
|
||||||
|
type Props = { numEtud: number };
|
||||||
|
|
||||||
|
function fmt(n: number): string {
|
||||||
|
return `${Math.round(n * 10) / 10}/20`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function noteClass(n: number): string {
|
||||||
|
return n >= 10 ? "note-chip note-chip--ok" : "note-chip note-chip--fail";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function NoteRecap({ numEtud }: Props) {
|
||||||
|
const [student, setStudent] = useState<Student | null>(null);
|
||||||
|
const [ueList, setUeList] = useState<UE[]>([]);
|
||||||
|
const [ueModules, setUeModules] = useState<UEModule[]>([]);
|
||||||
|
const [moduleMap, setModuleMap] = useState<Map<string, string>>(new Map());
|
||||||
|
const [noteMap, setNoteMap] = useState<Map<string, number>>(new Map());
|
||||||
|
const [ajustements, setAjustements] = useState<Ajustement[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [editingNote, setEditingNote] = useState<
|
||||||
|
{ idModule: string; value: string } | null
|
||||||
|
>(null);
|
||||||
|
const [ajustInputs, setAjustInputs] = useState<Record<number, string>>({});
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
const sRes = await fetch(`/students/api/students/${numEtud}`);
|
||||||
|
if (!sRes.ok) throw new Error("Élève introuvable");
|
||||||
|
const s: Student = await sRes.json();
|
||||||
|
setStudent(s);
|
||||||
|
|
||||||
|
const [uesRes, umRes, mRes, notesRes, ajustRes] = await Promise.all([
|
||||||
|
fetch("/notes/api/ues"),
|
||||||
|
fetch(
|
||||||
|
`/notes/api/ue-modules?idPromo=${encodeURIComponent(s.idPromo)}`,
|
||||||
|
),
|
||||||
|
fetch("/admin/api/modules"),
|
||||||
|
fetch(`/notes/api/notes?numEtud=${numEtud}`),
|
||||||
|
fetch(`/notes/api/ajustements?numEtud=${numEtud}`),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (uesRes.ok) setUeList(await uesRes.json());
|
||||||
|
if (umRes.ok) setUeModules(await umRes.json());
|
||||||
|
if (mRes.ok) {
|
||||||
|
const mods: Module[] = await mRes.json();
|
||||||
|
setModuleMap(new Map(mods.map((m) => [m.id, m.nom])));
|
||||||
|
}
|
||||||
|
if (notesRes.ok) {
|
||||||
|
const ns: Note[] = await notesRes.json();
|
||||||
|
setNoteMap(new Map(ns.map((n) => [n.idModule, n.note])));
|
||||||
|
}
|
||||||
|
if (ajustRes.ok) {
|
||||||
|
const aj: Ajustement[] = await ajustRes.json();
|
||||||
|
setAjustements(aj);
|
||||||
|
const inputs: Record<number, string> = {};
|
||||||
|
for (const a of aj) inputs[a.idUE] = String(a.valeur);
|
||||||
|
setAjustInputs(inputs);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "Erreur");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
load();
|
||||||
|
}, [numEtud]);
|
||||||
|
|
||||||
|
function calcAvg(ueMods: UEModule[]): number | null {
|
||||||
|
let total = 0, coeff = 0;
|
||||||
|
for (const um of ueMods) {
|
||||||
|
const n = noteMap.get(um.idModule);
|
||||||
|
if (n === undefined) return null;
|
||||||
|
total += n * um.coeff;
|
||||||
|
coeff += um.coeff;
|
||||||
|
}
|
||||||
|
return coeff > 0 ? total / coeff : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveNote(idModule: string, value: string) {
|
||||||
|
const note = parseFloat(value.replace(",", "."));
|
||||||
|
if (isNaN(note) || note < 0 || note > 20) {
|
||||||
|
setEditingNote(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const res = await fetch(
|
||||||
|
`/notes/api/notes/${numEtud}/${encodeURIComponent(idModule)}`,
|
||||||
|
{
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ note }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.ok) {
|
||||||
|
const updated: Note = await res.json();
|
||||||
|
setNoteMap((prev) => new Map(prev).set(idModule, updated.note));
|
||||||
|
}
|
||||||
|
setEditingNote(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function applyAjust(idUE: number) {
|
||||||
|
const val = parseFloat((ajustInputs[idUE] ?? "").replace(",", "."));
|
||||||
|
if (isNaN(val) || val < 0 || val > 20) return;
|
||||||
|
const existing = ajustements.find((a) => a.idUE === idUE);
|
||||||
|
const res = existing
|
||||||
|
? await fetch(`/notes/api/ajustements/${numEtud}/${idUE}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ valeur: val }),
|
||||||
|
})
|
||||||
|
: await fetch("/notes/api/ajustements", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ numEtud, idUE, valeur: val }),
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
const updated: Ajustement = await res.json();
|
||||||
|
setAjustements((prev) =>
|
||||||
|
existing
|
||||||
|
? prev.map((a) => a.idUE === idUE ? updated : a)
|
||||||
|
: [...prev, updated]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetAjust(idUE: number) {
|
||||||
|
const res = await fetch(`/notes/api/ajustements/${numEtud}/${idUE}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
setAjustements((prev) => prev.filter((a) => a.idUE !== idUE));
|
||||||
|
setAjustInputs((prev) => {
|
||||||
|
const c = { ...prev };
|
||||||
|
delete c[idUE];
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div class="page-content">
|
||||||
|
<p class="state-loading">Chargement…</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (error && !student) {
|
||||||
|
return (
|
||||||
|
<div class="page-content">
|
||||||
|
<p class="state-error">{error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!student) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="page-content">
|
||||||
|
<a
|
||||||
|
class="back-link"
|
||||||
|
href="/notes/courses"
|
||||||
|
f-partial="/notes/partials/courses"
|
||||||
|
>
|
||||||
|
← Retour à la liste
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<h2
|
||||||
|
class="page-title"
|
||||||
|
style="border-bottom: none; margin-bottom: 0.5rem"
|
||||||
|
>
|
||||||
|
Récap notes – {student.prenom} {student.nom}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="info-bar" style="margin-bottom: 1.25rem">
|
||||||
|
<span class="numEtud-chip">{student.numEtud}</span>
|
||||||
|
<span style="font-weight: 600">{student.prenom} {student.nom}</span>
|
||||||
|
<span class="note-chip note-chip--promo">{student.idPromo}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <p class="state-error">{error}</p>}
|
||||||
|
|
||||||
|
{ueList.length === 0
|
||||||
|
? (
|
||||||
|
<p class="state-empty">
|
||||||
|
Aucune UE configurée pour cette promotion.
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
: ueList.map((ue) => {
|
||||||
|
const ueMods = ueModules.filter((um) => um.idUE === ue.id);
|
||||||
|
const avg = calcAvg(ueMods);
|
||||||
|
const ajust = ajustements.find((a) => a.idUE === ue.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={ue.id} class="edit-section">
|
||||||
|
{/* UE header */}
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap">
|
||||||
|
<p class="edit-section-title" style="margin: 0">{ue.nom}</p>
|
||||||
|
{avg !== null && (
|
||||||
|
<span class={noteClass(avg)} style="font-size: 0.78rem">
|
||||||
|
Moy. calculée : {fmt(avg)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{ajust && (
|
||||||
|
<span
|
||||||
|
class="note-chip note-chip--ajust"
|
||||||
|
style="font-size: 0.78rem"
|
||||||
|
>
|
||||||
|
⚡ Ajust. actif : {fmt(ajust.valeur)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Module rows */}
|
||||||
|
{ueMods.length === 0
|
||||||
|
? (
|
||||||
|
<p
|
||||||
|
class="col-dim"
|
||||||
|
style="font-size: 0.8rem; padding: 0.25rem 0; margin-bottom: 0.75rem"
|
||||||
|
>
|
||||||
|
Aucun module associé à cette UE pour cette promotion.
|
||||||
|
</p>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<div style="margin-bottom: 0.75rem">
|
||||||
|
{ueMods.map((um) => {
|
||||||
|
const noteVal = noteMap.get(um.idModule);
|
||||||
|
const nomMod = moduleMap.get(um.idModule) ?? um.idModule;
|
||||||
|
const isEditing = editingNote?.idModule === um.idModule;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={um.idModule}
|
||||||
|
class="note-row"
|
||||||
|
>
|
||||||
|
<span class="note-row-label">
|
||||||
|
<span class="numEtud-chip note-row-chip">
|
||||||
|
{um.idModule}
|
||||||
|
</span>
|
||||||
|
{nomMod}
|
||||||
|
</span>
|
||||||
|
<span class="col-dim note-row-coef">
|
||||||
|
coef {um.coeff}
|
||||||
|
</span>
|
||||||
|
{isEditing
|
||||||
|
? (
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.25rem">
|
||||||
|
<input
|
||||||
|
class="form-input"
|
||||||
|
style="width: 5rem; text-align: center; font-size: 0.85rem"
|
||||||
|
value={editingNote!.value}
|
||||||
|
autoFocus
|
||||||
|
onInput={(e) =>
|
||||||
|
setEditingNote({
|
||||||
|
idModule: um.idModule,
|
||||||
|
value:
|
||||||
|
(e.target as HTMLInputElement).value,
|
||||||
|
})}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
saveNote(
|
||||||
|
um.idModule,
|
||||||
|
editingNote!.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setEditingNote(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onBlur={() =>
|
||||||
|
saveNote(um.idModule, editingNote!.value)}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class="col-dim"
|
||||||
|
style="font-size: 0.75rem"
|
||||||
|
>
|
||||||
|
/20
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<span
|
||||||
|
class={noteVal !== undefined
|
||||||
|
? noteClass(noteVal)
|
||||||
|
: "note-chip note-chip--none"}
|
||||||
|
style="font-size: 0.78rem; cursor: pointer"
|
||||||
|
title="Cliquer pour modifier"
|
||||||
|
onClick={() =>
|
||||||
|
setEditingNote({
|
||||||
|
idModule: um.idModule,
|
||||||
|
value: noteVal !== undefined
|
||||||
|
? String(noteVal)
|
||||||
|
: "",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{noteVal !== undefined ? fmt(noteVal) : "—/20"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-secondary"
|
||||||
|
style="font-size: 0.75rem"
|
||||||
|
onClick={() =>
|
||||||
|
setEditingNote({
|
||||||
|
idModule: um.idModule,
|
||||||
|
value: noteVal !== undefined
|
||||||
|
? String(noteVal)
|
||||||
|
: "",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
✏ note
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Ajustement */}
|
||||||
|
<div class="ajust-section">
|
||||||
|
<p class="ajust-title">Ajustement de la moyenne UE</p>
|
||||||
|
<p class="ajust-hint">
|
||||||
|
Override ponctuel – laisser vide pour utiliser la moy.
|
||||||
|
calculée
|
||||||
|
</p>
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap">
|
||||||
|
<div style="display: flex; align-items: center; gap: 0.25rem">
|
||||||
|
<input
|
||||||
|
class="form-input"
|
||||||
|
style="width: 4.5rem; text-align: center"
|
||||||
|
placeholder="—"
|
||||||
|
value={ajustInputs[ue.id] ?? ""}
|
||||||
|
onInput={(e) =>
|
||||||
|
setAjustInputs((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[ue.id]: (e.target as HTMLInputElement).value,
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
<span class="col-dim" style="font-size: 0.8rem">/20</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-primary"
|
||||||
|
onClick={() => applyAjust(ue.id)}
|
||||||
|
>
|
||||||
|
✓ Appliquer
|
||||||
|
</button>
|
||||||
|
{ajust && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-secondary"
|
||||||
|
onClick={() => resetAjust(ue.id)}
|
||||||
|
>
|
||||||
|
✕ Réinitialiser
|
||||||
|
</button>
|
||||||
|
<span
|
||||||
|
class="col-dim"
|
||||||
|
style="font-size: 0.75rem; font-family: monospace"
|
||||||
|
>
|
||||||
|
Affiché à l'élève : {fmt(ajust.valeur)}
|
||||||
|
{avg !== null ? ` (calculée : ${fmt(avg)})` : ""}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,83 +1,66 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { ajustements } from "$root/databases/schema.ts";
|
import { ajustements } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers = {
|
||||||
// #48 GET /ajustements
|
// #48 GET /ajustements
|
||||||
async GET(request) {
|
GET: withRules(["note_read"])(async (request, _context) => {
|
||||||
try {
|
const url = new URL(request.url);
|
||||||
const url = new URL(request.url);
|
const numEtudParam = url.searchParams.get("numEtud");
|
||||||
const numEtudParam = url.searchParams.get("numEtud");
|
const idUEParam = url.searchParams.get("idUE");
|
||||||
const idUEParam = url.searchParams.get("idUE");
|
|
||||||
|
|
||||||
let query = db.select().from(ajustements).$dynamic();
|
let query = db.select().from(ajustements).$dynamic();
|
||||||
|
|
||||||
if (numEtudParam) {
|
if (numEtudParam) {
|
||||||
const numEtud = parseInt(numEtudParam);
|
const numEtud = parseInt(numEtudParam);
|
||||||
if (isNaN(numEtud)) {
|
if (isNaN(numEtud)) {
|
||||||
return new Response("Paramètre numEtud invalide", { status: 400 });
|
return new Response("Paramètre numEtud invalide", { status: 400 });
|
||||||
}
|
|
||||||
query = query.where(eq(ajustements.numEtud, numEtud));
|
|
||||||
}
|
}
|
||||||
|
query = query.where(eq(ajustements.numEtud, numEtud));
|
||||||
if (idUEParam) {
|
|
||||||
const idUE = parseInt(idUEParam);
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return new Response("Paramètre idUE invalide", { status: 400 });
|
|
||||||
}
|
|
||||||
query = query.where(eq(ajustements.idUE, idUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await query;
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching ajustements:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
if (idUEParam) {
|
||||||
|
const idUE = parseInt(idUEParam);
|
||||||
|
if (isNaN(idUE)) {
|
||||||
|
return new Response("Paramètre idUE invalide", { status: 400 });
|
||||||
|
}
|
||||||
|
query = query.where(eq(ajustements.idUE, idUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await query;
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// #49 POST /ajustements
|
// #49 POST /ajustements
|
||||||
async POST(
|
POST: withRules(["note_write"])(async (request, _context) => {
|
||||||
request: Request,
|
const body: { numEtud: number; idUE: number; valeur: number } =
|
||||||
context: FreshContext<AuthenticatedState>,
|
await request.json();
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
if (!body.numEtud || !body.idUE || body.valeur === undefined) {
|
||||||
return new Response(null, { status: 403 });
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Champs requis: numEtud, idUE, valeur" }),
|
||||||
|
{ status: 400, headers: { "content-type": "application/json" } },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const [created] = await db
|
||||||
const body: { numEtud: number; idUE: number; valeur: number } =
|
.insert(ajustements)
|
||||||
await request.json();
|
.values({
|
||||||
|
numEtud: body.numEtud,
|
||||||
|
idUE: body.idUE,
|
||||||
|
valeur: body.valeur,
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
if (!body.numEtud || !body.idUE || body.valeur === undefined) {
|
return new Response(JSON.stringify(created), {
|
||||||
return new Response(
|
status: 201,
|
||||||
JSON.stringify({ error: "Champs requis: numEtud, idUE, valeur" }),
|
headers: { "content-type": "application/json" },
|
||||||
{ status: 400, headers: { "content-type": "application/json" } },
|
});
|
||||||
);
|
}),
|
||||||
}
|
|
||||||
|
|
||||||
const [created] = await db
|
|
||||||
.insert(ajustements)
|
|
||||||
.values({
|
|
||||||
numEtud: body.numEtud,
|
|
||||||
idUE: body.idUE,
|
|
||||||
valeur: body.valeur,
|
|
||||||
})
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(created), {
|
|
||||||
status: 201,
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating ajustement:", error);
|
|
||||||
return new Response("Failed to create ajustement", { status: 500 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,45 +1,41 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "../../../../databases/db.ts";
|
import { db } from "../../../../databases/db.ts";
|
||||||
import { notes } from "../../../../databases/schema.ts";
|
import { notes } from "../../../../databases/schema.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// #42 GET /notes
|
// #42 GET /notes
|
||||||
async GET(request) {
|
GET: withRules(["note_read", "own_note"])(async (request, _context) => {
|
||||||
try {
|
const url = new URL(request.url);
|
||||||
const url = new URL(request.url);
|
const numEtudParam = url.searchParams.get("numEtud");
|
||||||
const numEtudParam = url.searchParams.get("numEtud");
|
const idModule = url.searchParams.get("idModule");
|
||||||
const idModule = url.searchParams.get("idModule");
|
|
||||||
|
|
||||||
let query = db.select().from(notes).$dynamic();
|
let query = db.select().from(notes).$dynamic();
|
||||||
|
|
||||||
if (numEtudParam) {
|
if (numEtudParam) {
|
||||||
const numEtud = parseInt(numEtudParam);
|
const numEtud = parseInt(numEtudParam);
|
||||||
if (isNaN(numEtud)) {
|
if (isNaN(numEtud)) {
|
||||||
return new Response("Paramètre numEtud invalide", { status: 400 });
|
return new Response("Paramètre numEtud invalide", { status: 400 });
|
||||||
}
|
|
||||||
query = query.where(eq(notes.numEtud, numEtud));
|
|
||||||
}
|
}
|
||||||
|
query = query.where(eq(notes.numEtud, numEtud));
|
||||||
if (idModule) {
|
|
||||||
query = query.where(eq(notes.idModule, idModule));
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await query;
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching notes:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
if (idModule) {
|
||||||
|
query = query.where(eq(notes.idModule, idModule));
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await query;
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// #43 POST /notes
|
// #43 POST /notes
|
||||||
async POST(request) {
|
POST: withRules(["note_write", "own_teaching_note"])(
|
||||||
try {
|
async (request, _context) => {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { note, numEtud, idModule } = body;
|
const { note, numEtud, idModule } = body;
|
||||||
|
|
||||||
@@ -62,9 +58,6 @@ export const handler: Handlers = {
|
|||||||
status: 201,
|
status: 201,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
},
|
||||||
console.error("Error creating note:", error);
|
),
|
||||||
return new Response("Failed to create note", { status: 500 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,104 +1,109 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "../../../../../../databases/db.ts";
|
import { db } from "../../../../../../databases/db.ts";
|
||||||
import { notes } from "../../../../../../databases/schema.ts";
|
import { notes } from "../../../../../../databases/schema.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// #45 GET /notes/:numEtud/:idModule
|
// #45 GET /notes/:numEtud/:idModule
|
||||||
async GET(_request, context) {
|
GET: withRules(["note_read", "own_note", "own_teaching_note"])(
|
||||||
try {
|
async (_request, context) => {
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
try {
|
||||||
const { idModule } = context.params;
|
const numEtud = parseInt(context.params.numEtud);
|
||||||
|
const { idModule } = context.params;
|
||||||
|
|
||||||
if (isNaN(numEtud)) {
|
if (isNaN(numEtud)) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
||||||
{
|
{
|
||||||
status: 400,
|
status: 400,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
},
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.select().from(notes).where(
|
||||||
|
and(
|
||||||
|
eq(notes.numEtud, numEtud),
|
||||||
|
eq(notes.idModule, idModule),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Ressource introuvable" }),
|
||||||
|
{
|
||||||
|
status: 404,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching note:", error);
|
||||||
|
return new Response("Failed to fetch data", { status: 500 });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
const result = await db.select().from(notes).where(
|
),
|
||||||
and(
|
|
||||||
eq(notes.numEtud, numEtud),
|
|
||||||
eq(notes.idModule, idModule),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Ressource introuvable" }),
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching note:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// #46 PUT /notes/:numEtud/:idModule
|
// #46 PUT /notes/:numEtud/:idModule
|
||||||
async PUT(request, context) {
|
PUT: withRules(["note_write", "own_teaching_note"])(
|
||||||
try {
|
async (request, context) => {
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
try {
|
||||||
const { idModule } = context.params;
|
const numEtud = parseInt(context.params.numEtud);
|
||||||
|
const { idModule } = context.params;
|
||||||
|
|
||||||
if (isNaN(numEtud)) {
|
if (isNaN(numEtud)) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
JSON.stringify({ error: "Paramètre numEtud invalide" }),
|
||||||
{
|
{
|
||||||
status: 400,
|
status: 400,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await request.json();
|
||||||
|
const { note } = body;
|
||||||
|
|
||||||
|
if (note === undefined) {
|
||||||
|
return new Response("Champ 'note' manquant", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.update(notes).set({ note }).where(
|
||||||
|
and(
|
||||||
|
eq(notes.numEtud, numEtud),
|
||||||
|
eq(notes.idModule, idModule),
|
||||||
|
),
|
||||||
|
).returning();
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Ressource introuvable" }),
|
||||||
|
{
|
||||||
|
status: 404,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating note:", error);
|
||||||
|
return new Response("Failed to update note", { status: 500 });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
const body = await request.json();
|
),
|
||||||
const { note } = body;
|
|
||||||
|
|
||||||
if (note === undefined) {
|
|
||||||
return new Response("Champ 'note' manquant", { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.update(notes).set({ note }).where(
|
|
||||||
and(
|
|
||||||
eq(notes.numEtud, numEtud),
|
|
||||||
eq(notes.idModule, idModule),
|
|
||||||
),
|
|
||||||
).returning();
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Ressource introuvable" }),
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error updating note:", error);
|
|
||||||
return new Response("Failed to update note", { status: 500 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// #47 DELETE /notes/:numEtud/:idModule
|
// #47 DELETE /notes/:numEtud/:idModule
|
||||||
async DELETE(_request, context) {
|
DELETE: withRules(["note_write"])(async (_request, context) => {
|
||||||
try {
|
try {
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
const numEtud = parseInt(context.params.numEtud);
|
||||||
const { idModule } = context.params;
|
const { idModule } = context.params;
|
||||||
@@ -135,5 +140,5 @@ export const handler: Handlers = {
|
|||||||
console.error("Error deleting note:", error);
|
console.error("Error deleting note:", error);
|
||||||
return new Response("Failed to delete note", { status: 500 });
|
return new Response("Failed to delete note", { status: 500 });
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.3/package/types/index.d.ts"
|
||||||
|
import * as XLSX from "https://cdn.sheetjs.com/xlsx-0.20.3/package/xlsx.mjs";
|
||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import { db } from "../../../../../databases/db.ts";
|
||||||
|
import { notes } from "../../../../../databases/schema.ts";
|
||||||
|
|
||||||
|
export const handler: Handlers = {
|
||||||
|
//# 44 POST /notes/import-xlsx
|
||||||
|
async POST(request) {
|
||||||
|
try {
|
||||||
|
const formData = await request.formData();
|
||||||
|
const file = formData.get("file");
|
||||||
|
const idModule = formData.get("idModule");
|
||||||
|
|
||||||
|
if (!file || !(file instanceof File)) {
|
||||||
|
return new Response("Champ 'file' manquant", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!idModule || typeof idModule !== "string") {
|
||||||
|
return new Response("Champ 'idModule' manquant", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const buffer = await file.arrayBuffer();
|
||||||
|
const workbook = XLSX.read(buffer);
|
||||||
|
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||||
|
const rows = XLSX.utils.sheet_to_json(sheet) as {
|
||||||
|
numEtud: number;
|
||||||
|
note: number;
|
||||||
|
}[];
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const { numEtud, note } = row;
|
||||||
|
|
||||||
|
if (!numEtud || note === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.insert(notes)
|
||||||
|
.values({ numEtud, idModule, note })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: [notes.numEtud, notes.idModule],
|
||||||
|
set: { note },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(null, { status: 204 });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error importing notes:", error);
|
||||||
|
return new Response("Failed to import notes", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,72 +1,63 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "../../../../databases/db.ts";
|
import { db } from "../../../../databases/db.ts";
|
||||||
import { ueModules } from "../../../../databases/schema.ts";
|
import { ueModules } from "../../../../databases/schema.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// #37 GET /ue-modules
|
// #37 GET /ue-modules
|
||||||
async GET(request) {
|
GET: withRules(["note_read"])(async (request, _context) => {
|
||||||
try {
|
const url = new URL(request.url);
|
||||||
const url = new URL(request.url);
|
const idPromo = url.searchParams.get("idPromo");
|
||||||
const idPromo = url.searchParams.get("idPromo");
|
const idUEParam = url.searchParams.get("idUE");
|
||||||
const idUEParam = url.searchParams.get("idUE");
|
|
||||||
|
|
||||||
const idUE = idUEParam ? parseInt(idUEParam) : null;
|
const idUE = idUEParam ? parseInt(idUEParam) : null;
|
||||||
|
|
||||||
if (idUEParam && isNaN(idUE!)) {
|
if (idUEParam && isNaN(idUE!)) {
|
||||||
return new Response("Paramètre idUE invalide", { status: 400 });
|
return new Response("Paramètre idUE invalide", { status: 400 });
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.select().from(ueModules).where(
|
|
||||||
and(
|
|
||||||
idPromo ? eq(ueModules.idPromo, idPromo) : undefined,
|
|
||||||
idUE ? eq(ueModules.idUE, idUE) : undefined,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching UE-modules:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const result = await db.select().from(ueModules).where(
|
||||||
|
and(
|
||||||
|
idPromo ? eq(ueModules.idPromo, idPromo) : undefined,
|
||||||
|
idUE ? eq(ueModules.idUE, idUE) : undefined,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// #38 POST /ue-modules
|
// #38 POST /ue-modules
|
||||||
async POST(request) {
|
POST: withRules(["note_write"])(async (request, _context) => {
|
||||||
try {
|
const body = await request.json();
|
||||||
const body = await request.json();
|
const { idModule, idUE, idPromo, coeff } = body;
|
||||||
const { idModule, idUE, idPromo, coeff } = body;
|
|
||||||
|
|
||||||
if (!idModule || !idUE || !idPromo || coeff === undefined) {
|
if (!idModule || !idUE || !idPromo || coeff === undefined) {
|
||||||
return new Response(
|
return new Response(
|
||||||
"Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis",
|
"Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis",
|
||||||
{ status: 400 },
|
{ status: 400 },
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof coeff !== "number" || coeff < 0) {
|
|
||||||
return new Response("Champ 'coeff' doit être un nombre >= 0", {
|
|
||||||
status: 400,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.insert(ueModules).values({
|
|
||||||
idModule,
|
|
||||||
idUE,
|
|
||||||
idPromo,
|
|
||||||
coeff,
|
|
||||||
}).returning();
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 201,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating UE-module:", error);
|
|
||||||
return new Response("Failed to create UE-module", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
if (typeof coeff !== "number" || coeff < 0) {
|
||||||
|
return new Response("Champ 'coeff' doit être un nombre >= 0", {
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.insert(ueModules).values({
|
||||||
|
idModule,
|
||||||
|
idUE,
|
||||||
|
idPromo,
|
||||||
|
coeff,
|
||||||
|
}).returning();
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 201,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FreshContext, Handlers } from "$fresh/server.ts";
|
|||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { ueModules } from "$root/databases/schema.ts";
|
import { ueModules } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
const NOT_FOUND = new Response(
|
const NOT_FOUND = new Response(
|
||||||
@@ -9,8 +10,6 @@ const NOT_FOUND = new Response(
|
|||||||
{ status: 404, headers: { "content-type": "application/json" } },
|
{ status: 404, headers: { "content-type": "application/json" } },
|
||||||
);
|
);
|
||||||
|
|
||||||
const FORBIDDEN = new Response(null, { status: 403 });
|
|
||||||
|
|
||||||
const BAD_REQUEST = new Response(
|
const BAD_REQUEST = new Response(
|
||||||
JSON.stringify({ error: "Paramètres invalides" }),
|
JSON.stringify({ error: "Paramètres invalides" }),
|
||||||
{ status: 400, headers: { "content-type": "application/json" } },
|
{ status: 400, headers: { "content-type": "application/json" } },
|
||||||
@@ -18,29 +17,24 @@ const BAD_REQUEST = new Response(
|
|||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
// #39 GET /ue-modules/{idModule}/{idUE}/{idPromo}
|
// #39 GET /ue-modules/{idModule}/{idUE}/{idPromo}
|
||||||
async GET(
|
GET: withRules(["note_read"])(async (_request, context) => {
|
||||||
_request: Request,
|
const { idModule, idPromo } = (context as FreshContext<AuthenticatedState>)
|
||||||
context: FreshContext<AuthenticatedState>,
|
.params;
|
||||||
): Promise<Response> {
|
const idUE = Number(
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
(context as FreshContext<AuthenticatedState>).params.idUE,
|
||||||
return FORBIDDEN;
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const idModule = context.params.idModule;
|
if (isNaN(idUE)) return BAD_REQUEST;
|
||||||
const idUE = Number(context.params.idUE);
|
|
||||||
const idPromo = context.params.idPromo;
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return BAD_REQUEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ueModuleAssociation = await db
|
const ueModuleAssociation = await db
|
||||||
.select()
|
.select()
|
||||||
.from(ueModules)
|
.from(ueModules)
|
||||||
.where(
|
.where(
|
||||||
eq(ueModules.idModule, idModule),
|
and(
|
||||||
eq(ueModules.idUE, idUE),
|
eq(ueModules.idModule, idModule),
|
||||||
eq(ueModules.idPromo, idPromo),
|
eq(ueModules.idUE, idUE),
|
||||||
|
eq(ueModules.idPromo, idPromo),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.then((rows) => rows[0] ?? null);
|
.then((rows) => rows[0] ?? null);
|
||||||
|
|
||||||
@@ -49,24 +43,17 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(ueModuleAssociation), {
|
return new Response(JSON.stringify(ueModuleAssociation), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #40 PUT /ue-modules/{idModule}/{idUE}/{idPromo}
|
// #40 PUT /ue-modules/{idModule}/{idUE}/{idPromo}
|
||||||
async PUT(
|
PUT: withRules(["note_write"])(async (request, context) => {
|
||||||
request: Request,
|
const { idModule, idPromo } = (context as FreshContext<AuthenticatedState>)
|
||||||
context: FreshContext<AuthenticatedState>,
|
.params;
|
||||||
): Promise<Response> {
|
const idUE = Number(
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
(context as FreshContext<AuthenticatedState>).params.idUE,
|
||||||
return FORBIDDEN;
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const idModule = context.params.idModule;
|
if (isNaN(idUE)) return BAD_REQUEST;
|
||||||
const idUE = Number(context.params.idUE);
|
|
||||||
const idPromo = context.params.idPromo;
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return BAD_REQUEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
const body: { coeff: number } = await request.json();
|
const body: { coeff: number } = await request.json();
|
||||||
|
|
||||||
@@ -98,28 +85,19 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
idPromo: updated.idPromo,
|
idPromo: updated.idPromo,
|
||||||
coeff: updated.coeff,
|
coeff: updated.coeff,
|
||||||
}),
|
}),
|
||||||
{
|
{ headers: { "content-type": "application/json" } },
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #41 DELETE /ue-modules/{idModule}/{idUE}/{idPromo}
|
// #41 DELETE /ue-modules/{idModule}/{idUE}/{idPromo}
|
||||||
async DELETE(
|
DELETE: withRules(["note_write"])(async (_request, context) => {
|
||||||
_request: Request,
|
const { idModule, idPromo } = (context as FreshContext<AuthenticatedState>)
|
||||||
context: FreshContext<AuthenticatedState>,
|
.params;
|
||||||
): Promise<Response> {
|
const idUE = Number(
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
(context as FreshContext<AuthenticatedState>).params.idUE,
|
||||||
return FORBIDDEN;
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const idModule = context.params.idModule;
|
if (isNaN(idUE)) return BAD_REQUEST;
|
||||||
const idUE = Number(context.params.idUE);
|
|
||||||
const idPromo = context.params.idPromo;
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return BAD_REQUEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [deleted] = await db
|
const [deleted] = await db
|
||||||
.delete(ueModules)
|
.delete(ueModules)
|
||||||
@@ -135,5 +113,5 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
if (!deleted) return NOT_FOUND;
|
if (!deleted) return NOT_FOUND;
|
||||||
|
|
||||||
return new Response(null, { status: 204 });
|
return new Response(null, { status: 204 });
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,42 +1,33 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "../../../../databases/db.ts";
|
import { db } from "../../../../databases/db.ts";
|
||||||
import { ues } from "../../../../databases/schema.ts";
|
import { ues } from "../../../../databases/schema.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// #32 GET /ues
|
// #32 GET /ues
|
||||||
async GET() {
|
GET: withRules(["note_read"])(async (_request, _context) => {
|
||||||
try {
|
const result = await db.select().from(ues);
|
||||||
const result = await db.select().from(ues);
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result), {
|
return new Response(JSON.stringify(result), {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
});
|
});
|
||||||
} catch (error) {
|
}),
|
||||||
console.error("Error fetching UEs:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// #33 POST /ues
|
// #33 POST /ues
|
||||||
async POST(request) {
|
POST: withRules(["note_write"])(async (request, _context) => {
|
||||||
try {
|
const body = await request.json();
|
||||||
const body = await request.json();
|
const { nom } = body;
|
||||||
const { nom } = body;
|
|
||||||
|
|
||||||
if (!nom || !nom.trim()) {
|
if (!nom || !nom.trim()) {
|
||||||
return new Response("Champ 'nom' manquant", { status: 400 });
|
return new Response("Champ 'nom' manquant", { status: 400 });
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.insert(ues).values({ nom }).returning();
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 201,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating UE:", error);
|
|
||||||
return new Response("Failed to create UE", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const result = await db.insert(ues).values({ nom }).returning();
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 201,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,122 +1,90 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "../../../../../databases/db.ts";
|
import { db } from "../../../../../databases/db.ts";
|
||||||
import { ues } from "../../../../../databases/schema.ts";
|
import { ues } from "../../../../../databases/schema.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers = {
|
export const handler: Handlers = {
|
||||||
// # 34 GET /ues/:idUE
|
// #34 GET /ues/:idUE
|
||||||
async GET(_request, context) {
|
GET: withRules(["note_read"])(async (_request, context) => {
|
||||||
try {
|
const idUE = parseInt(context.params.idUE);
|
||||||
const idUE = parseInt(context.params.idUE);
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
if (isNaN(idUE)) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||||
{
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
||||||
status: 400,
|
);
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.select().from(ues).where(eq(ues.id, idUE));
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Ressource introuvable" }),
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching UE:", error);
|
|
||||||
return new Response("Failed to fetch data", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const result = await db.select().from(ues).where(eq(ues.id, idUE));
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Ressource introuvable" }),
|
||||||
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// #35 PUT /ues/:idUE
|
// #35 PUT /ues/:idUE
|
||||||
async PUT(request, context) {
|
PUT: withRules(["note_write"])(async (request, context) => {
|
||||||
try {
|
const idUE = parseInt(context.params.idUE);
|
||||||
const idUE = parseInt(context.params.idUE);
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
if (isNaN(idUE)) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||||
{
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
||||||
status: 400,
|
);
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await request.json();
|
|
||||||
const { nom } = body;
|
|
||||||
|
|
||||||
if (!nom) {
|
|
||||||
return new Response("Champ 'nom' manquant", { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.update(ues).set({ nom }).where(eq(ues.id, idUE))
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Ressource introuvable" }),
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(result[0]), {
|
|
||||||
status: 200,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error updating UE:", error);
|
|
||||||
return new Response("Failed to update UE", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const body = await request.json();
|
||||||
|
const { nom } = body;
|
||||||
|
|
||||||
|
if (!nom) {
|
||||||
|
return new Response("Champ 'nom' manquant", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.update(ues).set({ nom }).where(eq(ues.id, idUE))
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Ressource introuvable" }),
|
||||||
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 200,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
// #36 DELETE /ues/:idUE
|
// #36 DELETE /ues/:idUE
|
||||||
async DELETE(_request, context) {
|
DELETE: withRules(["note_write"])(async (_request, context) => {
|
||||||
try {
|
const idUE = parseInt(context.params.idUE);
|
||||||
const idUE = parseInt(context.params.idUE);
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
if (isNaN(idUE)) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
JSON.stringify({ error: "Paramètre idUE invalide" }),
|
||||||
{
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
||||||
status: 400,
|
);
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await db.delete(ues).where(eq(ues.id, idUE)).returning();
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Ressource introuvable" }),
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response(null, { status: 204 });
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error deleting UE:", error);
|
|
||||||
return new Response("Failed to delete UE", { status: 500 });
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
const result = await db.delete(ues).where(eq(ues.id, idUE)).returning();
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return new Response(
|
||||||
|
JSON.stringify({ error: "Ressource introuvable" }),
|
||||||
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(null, { status: 204 });
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import NoteRecap from "../(_islands)/NoteRecap.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
export default async function EditionPage(
|
||||||
|
_request: Request,
|
||||||
|
context: FreshContext<AuthenticatedState>,
|
||||||
|
) {
|
||||||
|
const numEtud = Number(context.params.numEtud);
|
||||||
|
return <NoteRecap numEtud={numEtud} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import NoteRecap from "../(_islands)/NoteRecap.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
export default async function RecapPage(
|
||||||
|
_request: Request,
|
||||||
|
context: FreshContext<AuthenticatedState>,
|
||||||
|
) {
|
||||||
|
const numEtud = Number(context.params.numEtud);
|
||||||
|
return <NoteRecap numEtud={numEtud} />;
|
||||||
|
}
|
||||||
@@ -1,35 +1,20 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { promotions } from "$root/databases/schema.ts";
|
import { promotions } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
// #13 GET /promotions
|
// #13 GET /promotions
|
||||||
async GET(
|
GET: withRules(["student_read"])(async (_request, _context) => {
|
||||||
_request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return new Response(JSON.stringify([]), {
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = await db.select().from(promotions);
|
const rows = await db.select().from(promotions);
|
||||||
return new Response(JSON.stringify(rows), {
|
return new Response(JSON.stringify(rows), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #14 POST /promotions
|
// #14 POST /promotions
|
||||||
async POST(
|
POST: withRules(["student_write"])(async (request, _context) => {
|
||||||
request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return new Response(null, { status: 403 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const body: { idPromo: string; annee: string } = await request.json();
|
const body: { idPromo: string; annee: string } = await request.json();
|
||||||
|
|
||||||
if (!body.idPromo || !body.annee) {
|
if (!body.idPromo || !body.annee) {
|
||||||
@@ -45,5 +30,5 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
status: 201,
|
status: 201,
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FreshContext, Handlers } from "$fresh/server.ts";
|
|||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { promotions } from "$root/databases/schema.ts";
|
import { promotions } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
const NOT_FOUND = new Response(
|
const NOT_FOUND = new Response(
|
||||||
@@ -9,22 +10,18 @@ const NOT_FOUND = new Response(
|
|||||||
{ status: 404, headers: { "content-type": "application/json" } },
|
{ status: 404, headers: { "content-type": "application/json" } },
|
||||||
);
|
);
|
||||||
|
|
||||||
const FORBIDDEN = new Response(null, { status: 403 });
|
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
// #15 GET /promotions/{idPromo}
|
// #15 GET /promotions/{idPromo}
|
||||||
async GET(
|
GET: withRules(["student_read"])(async (_request, context) => {
|
||||||
_request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const promo = await db
|
const promo = await db
|
||||||
.select()
|
.select()
|
||||||
.from(promotions)
|
.from(promotions)
|
||||||
.where(eq(promotions.id, context.params.idPromo))
|
.where(
|
||||||
|
eq(
|
||||||
|
promotions.id,
|
||||||
|
(context as FreshContext<AuthenticatedState>).params.idPromo,
|
||||||
|
),
|
||||||
|
)
|
||||||
.then((rows) => rows[0] ?? null);
|
.then((rows) => rows[0] ?? null);
|
||||||
|
|
||||||
if (!promo) return NOT_FOUND;
|
if (!promo) return NOT_FOUND;
|
||||||
@@ -32,23 +29,21 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(promo), {
|
return new Response(JSON.stringify(promo), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #16 PUT /promotions/{idPromo}
|
// #16 PUT /promotions/{idPromo}
|
||||||
async PUT(
|
PUT: withRules(["student_write"])(async (request, context) => {
|
||||||
request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const body: { annee: string } = await request.json();
|
const body: { annee: string } = await request.json();
|
||||||
|
|
||||||
const [updated] = await db
|
const [updated] = await db
|
||||||
.update(promotions)
|
.update(promotions)
|
||||||
.set({ annee: body.annee })
|
.set({ annee: body.annee })
|
||||||
.where(eq(promotions.id, context.params.idPromo))
|
.where(
|
||||||
|
eq(
|
||||||
|
promotions.id,
|
||||||
|
(context as FreshContext<AuthenticatedState>).params.idPromo,
|
||||||
|
),
|
||||||
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
if (!updated) return NOT_FOUND;
|
if (!updated) return NOT_FOUND;
|
||||||
@@ -56,24 +51,22 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(updated), {
|
return new Response(JSON.stringify(updated), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #17 DELETE /promotions/{idPromo}
|
// #17 DELETE /promotions/{idPromo}
|
||||||
async DELETE(
|
DELETE: withRules(["student_write"])(async (_request, context) => {
|
||||||
_request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [deleted] = await db
|
const [deleted] = await db
|
||||||
.delete(promotions)
|
.delete(promotions)
|
||||||
.where(eq(promotions.id, context.params.idPromo))
|
.where(
|
||||||
|
eq(
|
||||||
|
promotions.id,
|
||||||
|
(context as FreshContext<AuthenticatedState>).params.idPromo,
|
||||||
|
),
|
||||||
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
if (!deleted) return NOT_FOUND;
|
if (!deleted) return NOT_FOUND;
|
||||||
|
|
||||||
return new Response(null, { status: 204 });
|
return new Response(null, { status: 204 });
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,13 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { students } from "$root/databases/schema.ts";
|
import { students } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
// #7 GET /students
|
// #7 GET /students
|
||||||
async GET(
|
GET: withRules(["student_read"])(async (request, _context) => {
|
||||||
request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return new Response(JSON.stringify([]), {
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const idPromo = url.searchParams.get("idPromo");
|
const idPromo = url.searchParams.get("idPromo");
|
||||||
|
|
||||||
@@ -26,17 +18,10 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(rows), {
|
return new Response(JSON.stringify(rows), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #8 POST /students
|
// #8 POST /students
|
||||||
async POST(
|
POST: withRules(["student_write"])(async (request, _context) => {
|
||||||
request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return new Response(null, { status: 403 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const body: {
|
const body: {
|
||||||
numEtud: number;
|
numEtud: number;
|
||||||
nom: string;
|
nom: string;
|
||||||
@@ -57,5 +42,5 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
status: 201,
|
status: 201,
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FreshContext, Handlers } from "$fresh/server.ts";
|
|||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { students } from "$root/databases/schema.ts";
|
import { students } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
import { eq } from "npm:drizzle-orm@0.45.2";
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
||||||
|
|
||||||
const NOT_FOUND = new Response(
|
const NOT_FOUND = new Response(
|
||||||
@@ -9,19 +10,12 @@ const NOT_FOUND = new Response(
|
|||||||
{ status: 404, headers: { "content-type": "application/json" } },
|
{ status: 404, headers: { "content-type": "application/json" } },
|
||||||
);
|
);
|
||||||
|
|
||||||
const FORBIDDEN = new Response(null, { status: 403 });
|
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
// #10 GET /students/{numEtud}
|
// #10 GET /students/{numEtud}
|
||||||
async GET(
|
GET: withRules(["student_read"])(async (_request, context) => {
|
||||||
_request: Request,
|
const numEtud = Number(
|
||||||
context: FreshContext<AuthenticatedState>,
|
(context as FreshContext<AuthenticatedState>).params.numEtud,
|
||||||
): Promise<Response> {
|
);
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const numEtud = Number(context.params.numEtud);
|
|
||||||
const student = await db
|
const student = await db
|
||||||
.select()
|
.select()
|
||||||
.from(students)
|
.from(students)
|
||||||
@@ -33,18 +27,13 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(student), {
|
return new Response(JSON.stringify(student), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #11 PUT /students/{numEtud}
|
// #11 PUT /students/{numEtud}
|
||||||
async PUT(
|
PUT: withRules(["student_write"])(async (request, context) => {
|
||||||
request: Request,
|
const numEtud = Number(
|
||||||
context: FreshContext<AuthenticatedState>,
|
(context as FreshContext<AuthenticatedState>).params.numEtud,
|
||||||
): Promise<Response> {
|
);
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const numEtud = Number(context.params.numEtud);
|
|
||||||
const body: { nom: string; prenom: string; idPromo: string } = await request
|
const body: { nom: string; prenom: string; idPromo: string } = await request
|
||||||
.json();
|
.json();
|
||||||
|
|
||||||
@@ -59,18 +48,13 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify(updated), {
|
return new Response(JSON.stringify(updated), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
|
|
||||||
// #12 DELETE /students/{numEtud}
|
// #12 DELETE /students/{numEtud}
|
||||||
async DELETE(
|
DELETE: withRules(["student_write"])(async (_request, context) => {
|
||||||
_request: Request,
|
const numEtud = Number(
|
||||||
context: FreshContext<AuthenticatedState>,
|
(context as FreshContext<AuthenticatedState>).params.numEtud,
|
||||||
): Promise<Response> {
|
);
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
const numEtud = Number(context.params.numEtud);
|
|
||||||
const [deleted] = await db
|
const [deleted] = await db
|
||||||
.delete(students)
|
.delete(students)
|
||||||
.where(eq(students.numEtud, numEtud))
|
.where(eq(students.numEtud, numEtud))
|
||||||
@@ -79,5 +63,5 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
if (!deleted) return NOT_FOUND;
|
if (!deleted) return NOT_FOUND;
|
||||||
|
|
||||||
return new Response(null, { status: 204 });
|
return new Response(null, { status: 204 });
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
import { Handlers } from "$fresh/server.ts";
|
||||||
import { db } from "$root/databases/db.ts";
|
import { db } from "$root/databases/db.ts";
|
||||||
import { students } from "$root/databases/schema.ts";
|
import { students } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
import { withRules } from "$root/defaults/withRules.ts";
|
||||||
|
|
||||||
// #9 POST /students/import-csv
|
// #9 POST /students/import-csv
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
async POST(
|
POST: withRules(["student_write"])(async (request, _context) => {
|
||||||
request: Request,
|
|
||||||
context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
|
||||||
return new Response(null, { status: 403 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
const file = formData.get("file") as File | null;
|
const file = formData.get("file") as File | null;
|
||||||
const idPromo = formData.get("idPromo") as string | null;
|
const idPromo = formData.get("idPromo") as string | null;
|
||||||
@@ -60,5 +54,5 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response(JSON.stringify({ imported, errors }), {
|
return new Response(JSON.stringify({ imported, errors }), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -26,9 +26,9 @@ export default async function App(
|
|||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="/styles/main.css" />
|
<link rel="stylesheet" href="/styles/main.css" />
|
||||||
<link rel="stylesheet" href="/styles/app.css" />
|
<link rel="stylesheet" href="/styles/app.css" />
|
||||||
<link rel="stylesheet" href="styles/app-cards.css" />
|
<link rel="stylesheet" href="/styles/app-cards.css" />
|
||||||
<link rel="stylesheet" href="styles/students.css" />
|
<link rel="stylesheet" href="/styles/students.css" />
|
||||||
<link rel="stylesheet" href="styles/ui.css" />
|
<link rel="stylesheet" href="/styles/ui.css" />
|
||||||
</head>
|
</head>
|
||||||
<body f-client-nav>
|
<body f-client-nav>
|
||||||
<Header link={link} />
|
<Header link={link} />
|
||||||
|
|||||||
@@ -857,6 +857,96 @@
|
|||||||
font-size: 0.82rem;
|
font-size: 0.82rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------
|
||||||
|
Note recap chips & rows
|
||||||
|
------------------------------------------------------- */
|
||||||
|
.note-chip {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.15rem 0.55rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
font-family: monospace;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-chip--ok {
|
||||||
|
color: light-dark(var(--light-accent-color), var(--dark-accent-color));
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-chip--fail {
|
||||||
|
color: light-dark(#dc2626, #f87171);
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-chip--none {
|
||||||
|
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-chip--promo {
|
||||||
|
color: light-dark(var(--light-accent-color), var(--dark-accent-color));
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-chip--ajust {
|
||||||
|
color: #f59e0b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.4rem 0;
|
||||||
|
border-bottom: 1px solid
|
||||||
|
light-dark(var(--light-foreground-dimmer), var(--dark-foreground-dimmer));
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-row-label {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 10rem;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-row-chip {
|
||||||
|
font-size: 0.68rem;
|
||||||
|
padding: 0.1rem 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-row-coef {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ajust-section {
|
||||||
|
margin-top: 0.75rem;
|
||||||
|
padding-top: 0.65rem;
|
||||||
|
border-top: 1px solid
|
||||||
|
light-dark(var(--light-foreground-dimmer), var(--dark-foreground-dimmer));
|
||||||
|
}
|
||||||
|
|
||||||
|
.ajust-title {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
margin: 0 0 0.15rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ajust-hint {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
||||||
|
font-family: monospace;
|
||||||
|
margin: 0 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------
|
||||||
|
(end note recap)
|
||||||
|
------------------------------------------------------- */
|
||||||
|
|
||||||
.info-note-dim {
|
.info-note-dim {
|
||||||
font-size: 0.7rem;
|
font-size: 0.7rem;
|
||||||
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
||||||
|
|||||||
@@ -1,24 +1,40 @@
|
|||||||
// #115 - E2E tests for GET /permissions
|
// #115 - E2E tests for GET /permissions
|
||||||
// Handler statique (pas de DB), test direct du handler
|
|
||||||
|
|
||||||
import { assertEquals, assertExists } from "@std/assert";
|
import { assertEquals, assertExists } from "@std/assert";
|
||||||
import { makeEmployeeContext, makeGetRequest } from "../helpers/handler.ts";
|
import { makeEmployeeContext, makeGetRequest } from "../helpers/handler.ts";
|
||||||
|
import { seedPermissions, truncateAll } from "../helpers/db_integration.ts";
|
||||||
import { handler as permissionsHandler } from "$apps/admin/api/permissions.ts";
|
import { handler as permissionsHandler } from "$apps/admin/api/permissions.ts";
|
||||||
|
|
||||||
|
const PERMISSIONS = [
|
||||||
|
{ id: "note_read", nom: "Consulter les notes des étudiants" },
|
||||||
|
{ id: "note_write", nom: "Saisir et modifier les notes" },
|
||||||
|
{ id: "student_read", nom: "Consulter la liste des étudiants" },
|
||||||
|
{
|
||||||
|
id: "student_write",
|
||||||
|
nom: "Gérer les étudiants (ajout, modification, suppression)",
|
||||||
|
},
|
||||||
|
{ id: "module_read", nom: "Consulter les modules et enseignements" },
|
||||||
|
{ id: "module_write", nom: "Gérer les modules et enseignements" },
|
||||||
|
{ id: "user_read", nom: "Consulter les utilisateurs et leurs rôles" },
|
||||||
|
{ id: "user_write", nom: "Gérer les utilisateurs et leurs rôles" },
|
||||||
|
{ id: "role_write", nom: "Gérer les rôles et leurs permissions" },
|
||||||
|
];
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "e2e permissions: GET /permissions returns all 9 permissions",
|
name: "e2e permissions: GET /permissions returns all 9 permissions",
|
||||||
fn() {
|
async fn() {
|
||||||
const res = permissionsHandler.GET!(
|
await truncateAll();
|
||||||
|
await seedPermissions(PERMISSIONS);
|
||||||
|
const res = await permissionsHandler.GET!(
|
||||||
makeGetRequest("/permissions"),
|
makeGetRequest("/permissions"),
|
||||||
makeEmployeeContext(),
|
makeEmployeeContext(),
|
||||||
);
|
);
|
||||||
assertEquals(res.status, 200);
|
assertEquals(res.status, 200);
|
||||||
return res.text().then((text) => {
|
const text = await res.text();
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
assertEquals(data.length, 9);
|
assertEquals(data.length, 9);
|
||||||
assertExists(data.find((p: { id: string }) => p.id === "student_read"));
|
assertExists(data.find((p: { id: string }) => p.id === "student_read"));
|
||||||
assertExists(data.find((p: { id: string }) => p.id === "role_write"));
|
assertExists(data.find((p: { id: string }) => p.id === "role_write"));
|
||||||
});
|
|
||||||
},
|
},
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
@@ -27,7 +43,9 @@ Deno.test({
|
|||||||
Deno.test({
|
Deno.test({
|
||||||
name: "e2e permissions: GET /permissions - all entries have id and nom",
|
name: "e2e permissions: GET /permissions - all entries have id and nom",
|
||||||
async fn() {
|
async fn() {
|
||||||
const res = permissionsHandler.GET!(
|
await truncateAll();
|
||||||
|
await seedPermissions(PERMISSIONS);
|
||||||
|
const res = await permissionsHandler.GET!(
|
||||||
makeGetRequest("/permissions"),
|
makeGetRequest("/permissions"),
|
||||||
makeEmployeeContext(),
|
makeEmployeeContext(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -111,3 +111,9 @@ export async function seedAjustements(
|
|||||||
): Promise<typeof schema.ajustements.$inferSelect[]> {
|
): Promise<typeof schema.ajustements.$inferSelect[]> {
|
||||||
return await testDb.insert(schema.ajustements).values(rows).returning();
|
return await testDb.insert(schema.ajustements).values(rows).returning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function seedPermissions(
|
||||||
|
rows: { id: string; nom: string }[],
|
||||||
|
): Promise<typeof schema.permissions.$inferSelect[]> {
|
||||||
|
return await testDb.insert(schema.permissions).values(rows).returning();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user