From 9976b9e2b4ed192308343072405a93de574397ac Mon Sep 17 00:00:00 2001 From: Anys Date: Thu, 23 Apr 2026 13:03:23 +0200 Subject: [PATCH] feat(api): implement UE-Module association get endpoint - GET /ue-modules/{idModule}/{idUE}/{idPromo}: recover the detail of an ue-module association by its composite key - requires employee role --- .../ue-modules/[idModule]/[idUE]/[idPromo].ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts diff --git a/routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts b/routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts new file mode 100644 index 0000000..6a8ea5f --- /dev/null +++ b/routes/(apps)/notes/api/ue-modules/[idModule]/[idUE]/[idPromo].ts @@ -0,0 +1,53 @@ +import { FreshContext, Handlers } from "$fresh/server.ts"; +import { db } from "$root/databases/db.ts"; +import { ueModules } from "$root/databases/schema.ts"; +import { AuthenticatedState } from "$root/defaults/interfaces.ts"; +import { eq } from "npm:drizzle-orm@0.45.2"; + +const NOT_FOUND = new Response( + JSON.stringify({ error: "Association UE-Module introuvable" }), + { status: 404, headers: { "content-type": "application/json" } }, +); + +const FORBIDDEN = new Response(null, { status: 403 }); + +const BAD_REQUEST = new Response( + JSON.stringify({ error: "Paramètres invalides" }), + { status: 400, headers: { "content-type": "application/json" } }, +); + +export const handler: Handlers = { + // #39 GET /ue-modules/{idModule}/{idUE}/{idPromo} + async GET( + _request: Request, + context: FreshContext, + ): Promise { + if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { + return FORBIDDEN; + } + + const idModule = context.params.idModule; + const idUE = Number(context.params.idUE); + const idPromo = context.params.idPromo; + + if (isNaN(idUE)) { + return BAD_REQUEST; + } + + const ueModuleAssociation = await db + .select() + .from(ueModules) + .where( + eq(ueModules.idModule, idModule), + eq(ueModules.idUE, idUE), + eq(ueModules.idPromo, idPromo), + ) + .then((rows) => rows[0] ?? null); + + if (!ueModuleAssociation) return NOT_FOUND; + + return new Response(JSON.stringify(ueModuleAssociation), { + headers: { "content-type": "application/json" }, + }); + }, +}; -- 2.52.0