Compare commits
2 Commits
PMPR-112
...
60c8a6f3cf
| Author | SHA1 | Date | |
|---|---|---|---|
| 60c8a6f3cf | |||
| 088a1a6af2 |
@@ -0,0 +1,28 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import { db } from "../../../../databases/db.ts";
|
||||||
|
import { ueModules } from "../../../../databases/schema.ts";
|
||||||
|
import { and, eq } from "npm:drizzle-orm";
|
||||||
|
|
||||||
|
export const handler: Handlers = {
|
||||||
|
// #38 POST /ue-modules
|
||||||
|
async POST(request) {
|
||||||
|
try {
|
||||||
|
const body = await request.json();
|
||||||
|
const { idModule, idUE, idPromo, coeff } = body;
|
||||||
|
|
||||||
|
if (!idModule || !idUE || !idPromo || coeff === undefined) {
|
||||||
|
return new Response("Champs 'idModule', 'idUE', 'idPromo' et 'coeff' requis", { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.insert(ueModules).values({ idModule, idUE, idPromo, coeff }).returning();
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(result[0]), {
|
||||||
|
status: 201,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating UE-module:", error);
|
||||||
|
return new Response("Failed to create UE-module", { status: 500 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user