feat : fix a lot of stuff
This commit is contained in:
@@ -44,13 +44,25 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
||||
idPromo: string;
|
||||
} = await request.json();
|
||||
|
||||
if (!body.nom || !body.prenom || !body.idPromo) {
|
||||
if (!body.nom || !body.prenom) {
|
||||
return new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
const values: {
|
||||
numEtud?: number;
|
||||
nom: string;
|
||||
prenom: string;
|
||||
idPromo?: string;
|
||||
} = {
|
||||
nom: body.nom,
|
||||
prenom: body.prenom,
|
||||
};
|
||||
if (body.numEtud) values.numEtud = body.numEtud;
|
||||
if (body.idPromo) values.idPromo = body.idPromo;
|
||||
|
||||
const [created] = await db
|
||||
.insert(students)
|
||||
.values({ nom: body.nom, prenom: body.prenom, idPromo: body.idPromo })
|
||||
.values(values)
|
||||
.returning();
|
||||
|
||||
return new Response(JSON.stringify(created), {
|
||||
|
||||
Reference in New Issue
Block a user