Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b29b0cd19a |
@@ -41,9 +41,9 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// #51 PUT /ajustements/{numEtud}/{idUE}
|
// #52 DELETE /ajustements/{numEtud}/{idUE}
|
||||||
async PUT(
|
async DELETE(
|
||||||
request: Request,
|
_request: Request,
|
||||||
context: FreshContext<AuthenticatedState>,
|
context: FreshContext<AuthenticatedState>,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") {
|
||||||
@@ -57,25 +57,13 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
return new Response("Paramètres invalides", { status: 400 });
|
return new Response("Paramètres invalides", { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const body: { valeur: number } = await request.json();
|
const [deleted] = await db
|
||||||
|
.delete(ajustements)
|
||||||
if (body.valeur === undefined) {
|
|
||||||
return new Response(JSON.stringify({ error: "Champ requis: valeur" }), {
|
|
||||||
status: 400,
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const [updated] = await db
|
|
||||||
.update(ajustements)
|
|
||||||
.set({ valeur: body.valeur })
|
|
||||||
.where(eq(ajustements.numEtud, numEtud), eq(ajustements.idUE, idUE))
|
.where(eq(ajustements.numEtud, numEtud), eq(ajustements.idUE, idUE))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
if (!updated) return NOT_FOUND;
|
if (!deleted) return NOT_FOUND;
|
||||||
|
|
||||||
return new Response(JSON.stringify(updated), {
|
return new Response(null, { status: 204 });
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
import { Handlers } from "$fresh/server.ts";
|
|
||||||
import { db } from "../../../../../../databases/db.ts";
|
|
||||||
import { notes } from "../../../../../../databases/schema.ts";
|
|
||||||
import { and, eq } from "npm:drizzle-orm";
|
|
||||||
|
|
||||||
export const handler: Handlers = {
|
|
||||||
// #45 GET /notes/:numEtud/:idModule
|
|
||||||
async GET(_request, context) {
|
|
||||||
try {
|
|
||||||
const numEtud = parseInt(context.params.numEtud);
|
|
||||||
const { idModule } = context.params;
|
|
||||||
|
|
||||||
if (isNaN(numEtud)) {
|
|
||||||
return new Response(JSON.stringify({ error: "Paramètre numEtud invalide" }), {
|
|
||||||
status: 400,
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -34,70 +34,4 @@ export const handler: Handlers = {
|
|||||||
return new Response("Failed to fetch data", { status: 500 });
|
return new Response("Failed to fetch data", { status: 500 });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// #35 PUT /ues/:idUE
|
|
||||||
async PUT(request, context) {
|
|
||||||
try {
|
|
||||||
const idUE = parseInt(context.params.idUE);
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), {
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// #36 DELETE /ues/:idUE
|
|
||||||
async DELETE(_request, context) {
|
|
||||||
try {
|
|
||||||
const idUE = parseInt(context.params.idUE);
|
|
||||||
|
|
||||||
if (isNaN(idUE)) {
|
|
||||||
return new Response(JSON.stringify({ error: "Paramètre idUE invalide" }), {
|
|
||||||
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 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user