Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44857c668e | |||
| ac67593d5b |
@@ -34,4 +34,42 @@ 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 });
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user