Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f71128a7f3 | |||
| 720a380be8 | |||
| 6c602cb10a | |||
| bb09c1cce5 | |||
| f162fcaadc | |||
| 2c5e4ebf11 | |||
| 757e364af0 | |||
| 378cbb0c06 | |||
| d3de5c29e7 |
@@ -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:
|
||||||
|
|||||||
+19
-5
@@ -7,9 +7,6 @@ services:
|
|||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_DB: polympr_test
|
POSTGRES_DB: polympr_test
|
||||||
volumes:
|
volumes:
|
||||||
# Init script strips drizzle-kit markers and applies migrations on first start
|
|
||||||
- ./databases/docker-init.sh:/docker-entrypoint-initdb.d/01-migrate.sh:ro
|
|
||||||
- ./databases/migrations:/migrations:ro
|
|
||||||
- db_data_test:/var/lib/postgresql/data
|
- db_data_test:/var/lib/postgresql/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
@@ -17,6 +14,23 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
image: node:alpine
|
||||||
|
working_dir: /app
|
||||||
|
restart: "no"
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
command: node_modules/.bin/drizzle-kit migrate
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: db
|
||||||
|
POSTGRES_PORT: "5432"
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASS: testpass
|
||||||
|
POSTGRES_DB: polympr_test
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
app:
|
app:
|
||||||
image: denoland/deno:alpine
|
image: denoland/deno:alpine
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
@@ -34,8 +48,8 @@ services:
|
|||||||
POSTGRES_DB: polympr_test
|
POSTGRES_DB: polympr_test
|
||||||
LOCAL: "true"
|
LOCAL: "true"
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
migrate:
|
||||||
condition: service_healthy
|
condition: service_completed_successfully
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db_data_test:
|
db_data_test:
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
--> statement-breakpoint
|
||||||
|
INSERT INTO "permissions" ("id", "nom") VALUES
|
||||||
|
('note_read', 'Consulter les notes des étudiants'),
|
||||||
|
('note_write', 'Saisir et modifier les notes'),
|
||||||
|
('student_read', 'Consulter la liste des étudiants'),
|
||||||
|
('student_write','Gérer les étudiants (ajout, modification, suppression)'),
|
||||||
|
('module_read', 'Consulter les modules et enseignements'),
|
||||||
|
('module_write', 'Gérer les modules et enseignements'),
|
||||||
|
('user_read', 'Consulter 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');
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
-- Update permission names to French
|
||||||
|
-- This migration inserts or updates the permission labels used by the API.
|
||||||
|
--> statement-breakpoint
|
||||||
|
INSERT INTO "permissions" ("id", "nom") VALUES
|
||||||
|
('note_read', 'Consulter les notes des étudiants'),
|
||||||
|
('note_write', 'Saisir et modifier les notes'),
|
||||||
|
('student_read', 'Consulter la liste des étudiants'),
|
||||||
|
('student_write','Gérer les étudiants (ajout, modification, suppression)'),
|
||||||
|
('module_read', 'Consulter les modules et enseignements'),
|
||||||
|
('module_write', 'Gérer les modules et enseignements'),
|
||||||
|
('user_read', 'Consulter 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";
|
||||||
@@ -8,6 +8,20 @@
|
|||||||
"when": 1777155028708,
|
"when": 1777155028708,
|
||||||
"tag": "0000_square_jetstream",
|
"tag": "0000_square_jetstream",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777155028709,
|
||||||
|
"tag": "0001_seed_permissions",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 2,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777155028710,
|
||||||
|
"tag": "0002_update_permission_names",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,11 @@ 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_ues from "./routes/(apps)/notes/partials/(admin)/ues.tsx";
|
import * as $_apps_notes_partials_admin_ues from "./routes/(apps)/notes/partials/(admin)/ues.tsx";
|
||||||
import * as $_apps_notes_partials_index from "./routes/(apps)/notes/partials/index.tsx";
|
import * as $_apps_notes_partials_index from "./routes/(apps)/notes/partials/index.tsx";
|
||||||
import * as $_apps_notes_partials_notes from "./routes/(apps)/notes/partials/notes.tsx";
|
import * as $_apps_notes_partials_notes from "./routes/(apps)/notes/partials/notes.tsx";
|
||||||
@@ -72,6 +75,8 @@ import * as $_apps_mobility_islands_EditMobility from "./routes/(apps)/mobility/
|
|||||||
import * as $_apps_mobility_islands_ImportFile from "./routes/(apps)/mobility/(_islands)/ImportFile.tsx";
|
import * as $_apps_mobility_islands_ImportFile from "./routes/(apps)/mobility/(_islands)/ImportFile.tsx";
|
||||||
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_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";
|
||||||
@@ -126,9 +131,14 @@ 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":
|
||||||
|
$_apps_notes_partials_admin_import,
|
||||||
"./routes/(apps)/notes/partials/(admin)/ues.tsx":
|
"./routes/(apps)/notes/partials/(admin)/ues.tsx":
|
||||||
$_apps_notes_partials_admin_ues,
|
$_apps_notes_partials_admin_ues,
|
||||||
"./routes/(apps)/notes/partials/index.tsx": $_apps_notes_partials_index,
|
"./routes/(apps)/notes/partials/index.tsx": $_apps_notes_partials_index,
|
||||||
@@ -187,6 +197,10 @@ const manifest = {
|
|||||||
$_apps_notes_islands_AdminConsultNotes,
|
$_apps_notes_islands_AdminConsultNotes,
|
||||||
"./routes/(apps)/notes/(_islands)/AdminUEs.tsx":
|
"./routes/(apps)/notes/(_islands)/AdminUEs.tsx":
|
||||||
$_apps_notes_islands_AdminUEs,
|
$_apps_notes_islands_AdminUEs,
|
||||||
|
"./routes/(apps)/notes/(_islands)/ImportNotes.tsx":
|
||||||
|
$_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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,21 +171,19 @@ export default function AdminRoles() {
|
|||||||
<label
|
<label
|
||||||
key={p.id}
|
key={p.id}
|
||||||
class={`perm-toggle-card${active ? " active" : ""}`}
|
class={`perm-toggle-card${active ? " active" : ""}`}
|
||||||
onClick={() => togglePerm(p.id)}
|
|
||||||
>
|
>
|
||||||
<div class="perm-toggle-label">
|
<div class="perm-toggle-label">
|
||||||
<span class="perm-toggle-id">{p.id}</span>
|
<span class="perm-toggle-id">{p.id}</span>
|
||||||
<span class="perm-toggle-nom">{p.nom}</span>
|
<span class="perm-toggle-nom">{p.nom}</span>
|
||||||
</div>
|
</div>
|
||||||
<label class="toggle-switch">
|
<span class="toggle-switch">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={active}
|
checked={active}
|
||||||
onChange={() => togglePerm(p.id)}
|
onChange={() => togglePerm(p.id)}
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
/>
|
/>
|
||||||
<span class="toggle-slider" />
|
<span class="toggle-slider" />
|
||||||
</label>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
import { FreshContext, Handlers } from "$fresh/server.ts";
|
||||||
|
import { db } from "$root/databases/db.ts";
|
||||||
|
import { permissions } from "$root/databases/schema.ts";
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
|
||||||
const PERMISSIONS = [
|
|
||||||
{ id: "student_read", nom: "Consulter les élèves" },
|
|
||||||
{ id: "student_write", nom: "Gérer les élèves" },
|
|
||||||
{ id: "note_read", nom: "Consulter les notes" },
|
|
||||||
{ id: "note_write", nom: "Gérer les notes" },
|
|
||||||
{ id: "module_read", nom: "Consulter les modules" },
|
|
||||||
{ id: "module_write", nom: "Gérer les modules" },
|
|
||||||
{ id: "user_read", nom: "Consulter les utilisateurs" },
|
|
||||||
{ id: "user_write", nom: "Gérer les utilisateurs" },
|
|
||||||
{ id: "role_write", nom: "Gérer les rôles" },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
GET(_request, _context): Response {
|
async GET(
|
||||||
return new Response(JSON.stringify(PERMISSIONS), {
|
_request: Request,
|
||||||
|
_context: FreshContext<AuthenticatedState>,
|
||||||
|
): Promise<Response> {
|
||||||
|
const result = await db.select().from(permissions);
|
||||||
|
return new Response(JSON.stringify(result), {
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
// @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 { useRef } from "preact/hooks";
|
||||||
|
import { useSignal } from "@preact/signals";
|
||||||
|
|
||||||
|
export default function ImportNotes() {
|
||||||
|
const file = useSignal<File | null>(null);
|
||||||
|
const dragging = useSignal(false);
|
||||||
|
const uploading = useSignal(false);
|
||||||
|
const error = useSignal<string | null>(null);
|
||||||
|
const success = useSignal<string | null>(null);
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
function pickFile(f: File) {
|
||||||
|
if (!f.name.match(/\.xlsx?$/i)) {
|
||||||
|
error.value = "Fichier invalide — format attendu : .xlsx";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
file.value = f;
|
||||||
|
error.value = null;
|
||||||
|
success.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragOver(e: DragEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
dragging.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDragLeave() {
|
||||||
|
dragging.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDrop(e: DragEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
dragging.value = false;
|
||||||
|
const f = e.dataTransfer?.files?.[0];
|
||||||
|
if (f) pickFile(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputChange(e: Event) {
|
||||||
|
const f = (e.target as HTMLInputElement).files?.[0];
|
||||||
|
if (f) pickFile(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doImport() {
|
||||||
|
if (!file.value) return;
|
||||||
|
uploading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
success.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const arrayBuffer = await file.value.arrayBuffer();
|
||||||
|
const workbook = XLSX.read(arrayBuffer, { type: "array" });
|
||||||
|
let imported = 0;
|
||||||
|
let failed = 0;
|
||||||
|
|
||||||
|
for (const sheetName of workbook.SheetNames) {
|
||||||
|
const sheet = workbook.Sheets[sheetName];
|
||||||
|
const rows = XLSX.utils.sheet_to_json<{
|
||||||
|
numEtud: number;
|
||||||
|
idModule: string;
|
||||||
|
note: number;
|
||||||
|
}>(sheet, { header: ["numEtud", "idModule", "note"], range: 1 });
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const res = await fetch("/notes/api/notes", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify(row),
|
||||||
|
});
|
||||||
|
if (res.ok) imported++;
|
||||||
|
else failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
success.value = `Import terminé — ${imported} ajouté${
|
||||||
|
imported !== 1 ? "s" : ""
|
||||||
|
}${failed > 0 ? `, ${failed} erreur${failed !== 1 ? "s" : ""}` : ""}`;
|
||||||
|
} catch {
|
||||||
|
error.value = "Erreur lors de la lecture du fichier.";
|
||||||
|
} finally {
|
||||||
|
uploading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadTemplate() {
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
const ws = XLSX.utils.aoa_to_sheet([["numEtud", "idModule", "note"]]);
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, "Notes");
|
||||||
|
XLSX.writeFile(wb, "modele_notes.xlsx");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="file"
|
||||||
|
accept=".xlsx,.xls"
|
||||||
|
style="display:none"
|
||||||
|
onChange={onInputChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class={`drop-zone${dragging.value ? " dragging" : ""}`}
|
||||||
|
onDragOver={onDragOver}
|
||||||
|
onDragLeave={onDragLeave}
|
||||||
|
onDrop={onDrop}
|
||||||
|
onClick={() => inputRef.current?.click()}
|
||||||
|
>
|
||||||
|
<span class="drop-zone-icon">⬇</span>
|
||||||
|
{file.value ? <span class="drop-zone-file">{file.value.name}</span> : (
|
||||||
|
<>
|
||||||
|
<span class="drop-zone-text">Glisser le fichier .xlsx ici</span>
|
||||||
|
<span class="drop-zone-hint">ou cliquer pour parcourir</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error.value && <p class="state-error">{error.value}</p>}
|
||||||
|
{success.value && (
|
||||||
|
<p style="font-size:0.82rem; color: light-dark(var(--light-accent-color), var(--dark-accent-color)); margin-bottom: 0.75rem">
|
||||||
|
{success.value}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div class="upload-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-primary"
|
||||||
|
onClick={doImport}
|
||||||
|
disabled={!file.value || uploading.value}
|
||||||
|
>
|
||||||
|
{uploading.value ? "…" : "⊕ Importer"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-secondary"
|
||||||
|
onClick={downloadTemplate}
|
||||||
|
>
|
||||||
|
⊕ Télécharger Modèle
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="upload-format">
|
||||||
|
Format : <strong>numEtud</strong> | <strong>idModule</strong> |{" "}
|
||||||
|
<strong>note</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,8 +8,9 @@ const properties: AppProperties = {
|
|||||||
notes: "Mes notes",
|
notes: "Mes notes",
|
||||||
courses: "Consulter",
|
courses: "Consulter",
|
||||||
ues: "UEs",
|
ues: "UEs",
|
||||||
|
import: "Import xlsx",
|
||||||
},
|
},
|
||||||
adminOnly: ["courses", "ues"],
|
adminOnly: ["courses", "ues", "import"],
|
||||||
hint: "Student grading management",
|
hint: "Student grading management",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -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,29 @@
|
|||||||
|
import {
|
||||||
|
getPartialsConfig,
|
||||||
|
makePartials,
|
||||||
|
} from "$root/defaults/makePartials.tsx";
|
||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
import { State } from "$root/defaults/interfaces.ts";
|
||||||
|
import ImportNotes from "../../(_islands)/ImportNotes.tsx";
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async function ImportNotesPage(
|
||||||
|
_request: Request,
|
||||||
|
_context: FreshContext<State>,
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<div class="page-content">
|
||||||
|
<h2 class="page-title">Importer des Notes</h2>
|
||||||
|
<p
|
||||||
|
class="upload-format"
|
||||||
|
style="margin-bottom: 1.25rem"
|
||||||
|
>
|
||||||
|
POST /notes/api/notes
|
||||||
|
</p>
|
||||||
|
<ImportNotes />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = getPartialsConfig();
|
||||||
|
export default makePartials(ImportNotesPage);
|
||||||
@@ -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,111 +1,151 @@
|
|||||||
// @deno-types="https://cdn.sheetjs.com/xlsx-0.20.3/package/types/index.d.ts"
|
// @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 * as XLSX from "https://cdn.sheetjs.com/xlsx-0.20.3/package/xlsx.mjs";
|
||||||
import { Signal, useSignal } from "@preact/signals";
|
import { useRef } from "preact/hooks";
|
||||||
|
import { useSignal } from "@preact/signals";
|
||||||
|
|
||||||
/**
|
export default function UploadStudents() {
|
||||||
* Create a new handler for file change that displays
|
const file = useSignal<File | null>(null);
|
||||||
* messages in statusMessage and gets file data in fileData.
|
const dragging = useSignal(false);
|
||||||
* @param statusMessage The status message signal.
|
const uploading = useSignal(false);
|
||||||
* @param fileData The file data signal.
|
const error = useSignal<string | null>(null);
|
||||||
* @returns The file change handler.
|
const success = useSignal<string | null>(null);
|
||||||
*/
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
function getFileChangeHandler(
|
|
||||||
statusMessage: Signal<string>,
|
|
||||||
fileData: Signal<File | null>,
|
|
||||||
): (event: Event) => void {
|
|
||||||
/**
|
|
||||||
* Handle file change.
|
|
||||||
* @param event The file change event.
|
|
||||||
*/
|
|
||||||
return (event: Event) => {
|
|
||||||
const input = event.target as HTMLInputElement;
|
|
||||||
if (input.files && input.files.length > 0) {
|
|
||||||
fileData.value = input.files[0];
|
|
||||||
statusMessage.value = `File selected: ${input.files[0].name}`;
|
|
||||||
} else {
|
|
||||||
fileData.value = null;
|
|
||||||
statusMessage.value = "No file selected";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
function pickFile(f: File) {
|
||||||
* Create a new handler that sends data file to server.
|
if (!f.name.match(/\.xlsx?$/i)) {
|
||||||
* @param statusMessage The status message signal.
|
error.value = "Fichier invalide — format attendu : .xlsx";
|
||||||
* @param fileData The file data signal.
|
|
||||||
* @returns The file confirmation handler.
|
|
||||||
*/
|
|
||||||
function getUploadConfirmationFunction(
|
|
||||||
statusMessage: Signal<string>,
|
|
||||||
fileData: Signal<File | null>,
|
|
||||||
): () => void {
|
|
||||||
/**
|
|
||||||
* Add students to database.
|
|
||||||
* @returns Confirm upload of students.
|
|
||||||
*/
|
|
||||||
return () => {
|
|
||||||
if (!fileData.value) {
|
|
||||||
statusMessage.value = "Please select a file before confirming upload.";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
file.value = f;
|
||||||
|
error.value = null;
|
||||||
|
success.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
const reader = new FileReader();
|
function onDragOver(e: DragEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
dragging.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
function onDragLeave() {
|
||||||
* Send all data to the server.
|
dragging.value = false;
|
||||||
* @param event The finished progress event.
|
}
|
||||||
*/
|
|
||||||
reader.onload = async (event: ProgressEvent<FileReader>) => {
|
function onDrop(e: DragEvent) {
|
||||||
const arrayBuffer = event.target!.result as ArrayBuffer;
|
e.preventDefault();
|
||||||
|
dragging.value = false;
|
||||||
|
const f = e.dataTransfer?.files?.[0];
|
||||||
|
if (f) pickFile(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputChange(e: Event) {
|
||||||
|
const f = (e.target as HTMLInputElement).files?.[0];
|
||||||
|
if (f) pickFile(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doImport() {
|
||||||
|
if (!file.value) return;
|
||||||
|
uploading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
success.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const arrayBuffer = await file.value.arrayBuffer();
|
||||||
const workbook = XLSX.read(arrayBuffer, { type: "array" });
|
const workbook = XLSX.read(arrayBuffer, { type: "array" });
|
||||||
let allOK = true;
|
let imported = 0;
|
||||||
|
let failed = 0;
|
||||||
|
|
||||||
for (const sheetName of workbook.SheetNames) {
|
for (const sheetName of workbook.SheetNames) {
|
||||||
const sheet = workbook.Sheets[sheetName];
|
const sheet = workbook.Sheets[sheetName];
|
||||||
const data = XLSX.utils.sheet_to_json(sheet, {
|
const rows = XLSX.utils.sheet_to_json<{
|
||||||
header: ["userId", "lastName", "firstName", "mail"],
|
numEtud: number;
|
||||||
range: 1,
|
nom: string;
|
||||||
});
|
prenom: string;
|
||||||
|
}>(sheet, { header: ["numEtud", "nom", "prenom"], range: 1 });
|
||||||
|
|
||||||
const response = await fetch("/students/api/students", {
|
for (const row of rows) {
|
||||||
|
const res = await fetch("/students/api/students", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: JSON.stringify({ promoName: sheetName, data }),
|
body: JSON.stringify({ ...row, idPromo: sheetName }),
|
||||||
});
|
});
|
||||||
|
if (res.ok) imported++;
|
||||||
if (!response.ok) {
|
else failed++;
|
||||||
allOK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statusMessage.value = allOK
|
success.value = `Import terminé — ${imported} ajouté${
|
||||||
? "Failed to insert all data."
|
imported !== 1 ? "s" : ""
|
||||||
: "Data uploaded and inserted successfully!";
|
}${failed > 0 ? `, ${failed} erreur${failed !== 1 ? "s" : ""}` : ""}`;
|
||||||
};
|
} catch {
|
||||||
|
error.value = "Erreur lors de la lecture du fichier.";
|
||||||
/**
|
} finally {
|
||||||
* Display error message if any.
|
uploading.value = false;
|
||||||
*/
|
}
|
||||||
reader.onerror = () => {
|
|
||||||
statusMessage.value = "Error reading the file.";
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsArrayBuffer(fileData.value);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function UploadStudents() {
|
function downloadTemplate() {
|
||||||
const statusMessage = useSignal<string>("");
|
const wb = XLSX.utils.book_new();
|
||||||
const fileData = useSignal<File | null>(null);
|
const ws = XLSX.utils.aoa_to_sheet([["numEtud", "nom", "prenom"]]);
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, "4A22");
|
||||||
const handleFileChange = getFileChangeHandler(statusMessage, fileData);
|
XLSX.writeFile(wb, "modele_etudiants.xlsx");
|
||||||
const confirmUpload = getUploadConfirmationFunction(statusMessage, fileData);
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="file"
|
||||||
|
accept=".xlsx,.xls"
|
||||||
|
style="display:none"
|
||||||
|
onChange={onInputChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class={`drop-zone${dragging.value ? " dragging" : ""}`}
|
||||||
|
onDragOver={onDragOver}
|
||||||
|
onDragLeave={onDragLeave}
|
||||||
|
onDrop={onDrop}
|
||||||
|
onClick={() => inputRef.current?.click()}
|
||||||
|
>
|
||||||
|
<span class="drop-zone-icon">⬇</span>
|
||||||
|
{file.value ? <span class="drop-zone-file">{file.value.name}</span> : (
|
||||||
<>
|
<>
|
||||||
<input type="file" accept=".xlsx, .xls" onChange={handleFileChange} />
|
<span class="drop-zone-text">Glisser le fichier .xlsx ici</span>
|
||||||
<button type="button" onClick={confirmUpload}>Confirm Upload</button>
|
<span class="drop-zone-hint">ou cliquer pour parcourir</span>
|
||||||
<p>{statusMessage.value}</p>
|
|
||||||
</>
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error.value && <p class="state-error">{error.value}</p>}
|
||||||
|
{success.value && (
|
||||||
|
<p style="font-size:0.82rem; color: light-dark(var(--light-accent-color), var(--dark-accent-color)); margin-bottom: 0.75rem">
|
||||||
|
{success.value}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div class="upload-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-primary"
|
||||||
|
onClick={doImport}
|
||||||
|
disabled={!file.value || uploading.value}
|
||||||
|
>
|
||||||
|
{uploading.value ? "…" : "⊕ Importer"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-secondary"
|
||||||
|
onClick={downloadTemplate}
|
||||||
|
>
|
||||||
|
⊕ Télécharger Modèle
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="upload-format">
|
||||||
|
Format : <strong>promo</strong> (nom de la feuille) |{" "}
|
||||||
|
<strong>numEtud</strong> | <strong>nom</strong> |{" "}
|
||||||
|
<strong>prénom</strong>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,16 @@ import { State } from "$root/defaults/interfaces.ts";
|
|||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function Students(_request: Request, _context: FreshContext<State>) {
|
async function Students(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<div class="page-content">
|
||||||
<h2>Upload Students</h2>
|
<h2 class="page-title">Importer des Élèves</h2>
|
||||||
|
<p
|
||||||
|
class="upload-format"
|
||||||
|
style="margin-bottom: 1.25rem"
|
||||||
|
>
|
||||||
|
POST /students/api/students/import-csv
|
||||||
|
</p>
|
||||||
<UploadStudents />
|
<UploadStudents />
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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} />
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
font-family: var(--font-family-text);
|
font-family: var(--font-family-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-size: 130%; /* scale up from browser default 16px → ~20.8px */
|
||||||
|
}
|
||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
+154
-1
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
.page-content {
|
.page-content {
|
||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
max-width: 960px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-title {
|
.page-title {
|
||||||
@@ -783,6 +782,70 @@
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------
|
||||||
|
File drop zone (import pages)
|
||||||
|
------------------------------------------------------- */
|
||||||
|
|
||||||
|
.drop-zone {
|
||||||
|
border: 2px dashed
|
||||||
|
light-dark(var(--light-foreground-dimmer), var(--dark-foreground-dimmer));
|
||||||
|
border-radius: 6px;
|
||||||
|
background: light-dark(white, #141228);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
padding: 3rem 2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 150ms, background 150ms;
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone:hover,
|
||||||
|
.drop-zone.dragging {
|
||||||
|
border-color: light-dark(var(--light-accent-color), var(--dark-accent-color));
|
||||||
|
background: light-dark(#f0fff4, #0a1a10);
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone-icon {
|
||||||
|
font-size: 2.4rem;
|
||||||
|
line-height: 1;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone-text {
|
||||||
|
font-size: 0.88rem;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone-hint {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-family: monospace;
|
||||||
|
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone-file {
|
||||||
|
font-size: 0.78rem;
|
||||||
|
font-family: monospace;
|
||||||
|
color: light-dark(var(--light-accent-color), var(--dark-accent-color));
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.75rem;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-format {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-family: monospace;
|
||||||
|
color: light-dark(var(--light-foreground-dim), var(--dark-foreground-dim));
|
||||||
|
}
|
||||||
|
|
||||||
/* Info note box */
|
/* Info note box */
|
||||||
.info-note {
|
.info-note {
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.75rem 1rem;
|
||||||
@@ -794,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