Compare commits

..

1 Commits

Author SHA1 Message Date
Clément Oudelet 32ffbb7cda PMPR-32 : GET /ues - liste toutes les UEs 2026-04-22 12:50:46 +02:00
2 changed files with 67 additions and 48 deletions
+47 -47
View File
@@ -1,59 +1,70 @@
import { import {
date, doublePrecision,
integer, integer,
pgTable, pgTable,
primaryKey, primaryKey,
real,
serial, serial,
text, text,
} from "npm:drizzle-orm/pg-core"; } from "npm:drizzle-orm/pg-core";
// Ancien schéma conservé
export const promotions = pgTable("promotions", {
id: text("idPromo").primaryKey(),
annee: text("annee"),
});
export const students = pgTable("students", {
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.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", { export const roles = pgTable("roles", {
id: serial("id").primaryKey(), id: serial("id").primaryKey(),
nom: text("nom").notNull(), nom: text("nom"),
}); });
export const permissions = pgTable("permissions", { export const permissions = pgTable("permissions", {
id: text("id").primaryKey(), id: serial("id").primaryKey(),
nom: text("nom").notNull(), nom: text("nom"),
}); });
export const rolePermissions = pgTable("role_permissions", { export const rolePermissions = pgTable("role_permissions", {
idRole: integer("idRole").notNull().references(() => roles.id), idRole: integer("idRole").references(() => roles.id),
idPermission: text("idPermission").notNull().references(() => permissions.id), idPermission: integer("idPermission").references(() => permissions.id),
}, (t) => ({ }, (t) => ({
pk: primaryKey({ columns: [t.idRole, t.idPermission] }), pk: primaryKey({ columns: [t.idRole, t.idPermission] }),
})); }));
export const users = pgTable("users", { export const users = pgTable("users", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
nom: text("nom").notNull(), nom: text("nom"),
prenom: text("prenom").notNull(), prenom: text("prenom"),
idRole: integer("idRole").references(() => roles.id), idRole: integer("idRole").references(() => roles.id),
}); });
export const promotions = pgTable("promotions", {
id: serial("id").primaryKey(),
endyear: integer("endyear"),
current: integer("current"),
});
export const students = pgTable("students", {
numEtud: serial("numEtud").primaryKey(),
nom: text("nom").notNull(),
prenom: text("prenom").notNull(),
idPromo: text("idPromo").references(() => promotions.id as unknown as string),
});
export const modules = pgTable("modules", { export const modules = pgTable("modules", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
nom: text("nom").notNull(), nom: text("nom"),
}); });
export const enseignements = pgTable("enseignements", { export const enseignements = pgTable("enseignements", {
idProf: text("idProf").notNull().references(() => users.id), idProf: text("idProf").references(() => users.id),
idModule: text("idModule").notNull().references(() => modules.id), idModule: text("idModule").references(() => modules.id),
idPromo: text("idPromo").notNull(), idPromo: text("idPromo").references(() => promotions.id),
}, (t) => ({ }, (t) => ({
pk: primaryKey({ columns: [t.idProf, t.idModule, t.idPromo] }), pk: primaryKey({ columns: [t.idProf, t.idModule, t.idPromo] }),
})); }));
@@ -64,37 +75,26 @@ export const ues = pgTable("ues", {
}); });
export const ueModules = pgTable("ue_modules", { export const ueModules = pgTable("ue_modules", {
idModule: text("idModule").notNull().references(() => modules.id), idModule: text("idModule").references(() => modules.id),
idUE: integer("idUE").notNull().references(() => ues.id), idUE: integer("idUE").references(() => ues.id),
idPromo: text("idPromo").notNull(), idPromo: text("idPromo").references(() => promotions.id),
coeff: real("coeff").notNull(), coeff: doublePrecision("coeff"),
}, (t) => ({ }, (t) => ({
pk: primaryKey({ columns: [t.idModule, t.idUE, t.idPromo] }), pk: primaryKey({ columns: [t.idModule, t.idUE, t.idPromo] }),
})); }));
export const notes = pgTable("notes", { export const notes = pgTable("notes", {
numEtud: integer("numEtud").notNull().references(() => students.numEtud), numEtud: integer("numEtud").references(() => students.numEtud),
idModule: text("idModule").notNull().references(() => modules.id), idModule: text("idModule").references(() => modules.id),
note: real("note").notNull(), note: doublePrecision("note"),
}, (t) => ({ }, (t) => ({
pk: primaryKey({ columns: [t.numEtud, t.idModule] }), pk: primaryKey({ columns: [t.numEtud, t.idModule] }),
})); }));
export const ajustements = pgTable("ajustements", { export const ajustements = pgTable("ajustements", {
numEtud: integer("numEtud").notNull().references(() => students.numEtud), numEtud: integer("numEtud").references(() => students.numEtud),
idUE: integer("idUE").notNull().references(() => ues.id), idUE: integer("idUE").references(() => ues.id),
valeur: real("valeur").notNull(), valeur: doublePrecision("valeur"),
}, (t) => ({ }, (t) => ({
pk: primaryKey({ columns: [t.numEtud, t.idUE] }), pk: primaryKey({ columns: [t.numEtud, t.idUE] }),
})); }));
export const mobility = pgTable("mobility", {
id: serial("id").primaryKey(),
studentId: integer("studentId").references(() => students.numEtud),
startDate: date("startDate"),
endDate: date("endDate"),
weeksCount: integer("weeksCount"),
destinationCountry: text("destinationCountry"),
destinationName: text("destinationName"),
mobilityStatus: text("mobilityStatus").default("N/A"),
});
+19
View File
@@ -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 });
}
},
};