From 32ffbb7cda4619ae1761078712d4646544904362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudelet?= Date: Wed, 22 Apr 2026 12:50:46 +0200 Subject: [PATCH] PMPR-32 : GET /ues - liste toutes les UEs --- databases/schema.ts | 92 +++++++++++++++++++++++++++++----- routes/(apps)/notes/api/ues.ts | 19 +++++++ 2 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 routes/(apps)/notes/api/ues.ts diff --git a/databases/schema.ts b/databases/schema.ts index 1d7632e..d9fcc1a 100644 --- a/databases/schema.ts +++ b/databases/schema.ts @@ -1,32 +1,100 @@ import { - date, + doublePrecision, integer, pgTable, + primaryKey, serial, text, } from "npm:drizzle-orm/pg-core"; +// Ancien schéma conservé export const promotions = pgTable("promotions", { - id: serial("id").primaryKey(), - endyear: integer("endyear"), - current: integer("current"), + id: text("idPromo").primaryKey(), + annee: text("annee"), }); export const students = pgTable("students", { - userId: text("userId").primaryKey(), - firstName: text("firstName"), - lastName: text("lastName"), - mail: text("mail"), - promotionId: integer("promotionId").references(() => promotions.id), + numEtud: serial("numEtud").primaryKey(), + nom: text("nom"), + prenom: text("prenom"), + idPromo: text("idPromo").references(() => promotions.id), }); export const mobility = pgTable("mobility", { id: serial("id").primaryKey(), - studentId: text("studentId").references(() => students.userId), - startDate: date("startDate"), - endDate: date("endDate"), + studentId: text("studentId").references(() => students.numEtud), + startDate: text("startDate"), + endDate: text("endDate"), weeksCount: integer("weeksCount"), destinationCountry: text("destinationCountry"), destinationName: text("destinationName"), mobilityStatus: text("mobilityStatus").default("N/A"), }); + +// Nouveau schéma +export const roles = pgTable("roles", { + id: serial("id").primaryKey(), + nom: text("nom"), +}); + +export const permissions = pgTable("permissions", { + id: serial("id").primaryKey(), + nom: text("nom"), +}); + +export const rolePermissions = pgTable("role_permissions", { + idRole: integer("idRole").references(() => roles.id), + idPermission: integer("idPermission").references(() => permissions.id), +}, (t) => ({ + pk: primaryKey({ columns: [t.idRole, t.idPermission] }), +})); + +export const users = pgTable("users", { + id: text("id").primaryKey(), + nom: text("nom"), + prenom: text("prenom"), + idRole: integer("idRole").references(() => roles.id), +}); + +export const modules = pgTable("modules", { + id: text("id").primaryKey(), + nom: text("nom"), +}); + +export const enseignements = pgTable("enseignements", { + idProf: text("idProf").references(() => users.id), + idModule: text("idModule").references(() => modules.id), + idPromo: text("idPromo").references(() => promotions.id), +}, (t) => ({ + pk: primaryKey({ columns: [t.idProf, t.idModule, t.idPromo] }), +})); + +export const ues = pgTable("ues", { + id: serial("id").primaryKey(), + nom: text("nom").notNull(), +}); + +export const ueModules = pgTable("ue_modules", { + idModule: text("idModule").references(() => modules.id), + idUE: integer("idUE").references(() => ues.id), + idPromo: text("idPromo").references(() => promotions.id), + coeff: doublePrecision("coeff"), +}, (t) => ({ + pk: primaryKey({ columns: [t.idModule, t.idUE, t.idPromo] }), +})); + +export const notes = pgTable("notes", { + numEtud: integer("numEtud").references(() => students.numEtud), + idModule: text("idModule").references(() => modules.id), + note: doublePrecision("note"), +}, (t) => ({ + pk: primaryKey({ columns: [t.numEtud, t.idModule] }), +})); + +export const ajustements = pgTable("ajustements", { + numEtud: integer("numEtud").references(() => students.numEtud), + idUE: integer("idUE").references(() => ues.id), + valeur: doublePrecision("valeur"), +}, (t) => ({ + pk: primaryKey({ columns: [t.numEtud, t.idUE] }), +})); \ No newline at end of file diff --git a/routes/(apps)/notes/api/ues.ts b/routes/(apps)/notes/api/ues.ts new file mode 100644 index 0000000..562ca90 --- /dev/null +++ b/routes/(apps)/notes/api/ues.ts @@ -0,0 +1,19 @@ +import { Handlers } from "$fresh/server.ts"; +import { db } from "../../../../databases/db.ts"; +import { ues } from "../../../../databases/schema.ts"; + +export const handler: Handlers = { + async GET() { + try { + const result = await db.select().from(ues); + + return new Response(JSON.stringify(result), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); + } catch (error) { + console.error("Error fetching UEs:", error); + return new Response("Failed to fetch data", { status: 500 }); + } + }, +}; \ No newline at end of file -- 2.52.0