Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9168ca53da |
@@ -0,0 +1,13 @@
|
|||||||
|
import { AppProperties } from "$root/defaults/interfaces.ts";
|
||||||
|
|
||||||
|
const properties: AppProperties = {
|
||||||
|
name: "Admin",
|
||||||
|
icon: "school",
|
||||||
|
pages: {
|
||||||
|
index: "Homepage",
|
||||||
|
},
|
||||||
|
adminOnly: [],
|
||||||
|
hint: "PolyMPR module",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default properties;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export const handler: Handlers = {
|
||||||
|
async POST(request, context) {
|
||||||
|
if (request.headers.get("content-type") != "application/json") {
|
||||||
|
return new Response(null, {
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseBody = {
|
||||||
|
requestBody: await request.json(),
|
||||||
|
context,
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(responseBody), {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Handlers } from "$fresh/server.ts";
|
||||||
|
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
||||||
|
|
||||||
|
const PERMISSIONS = [
|
||||||
|
{ id: "student_read", nom: "Consulter les élèves" },
|
||||||
|
{ id: "student_write", nom: "Gérer les élèves" },
|
||||||
|
{ id: "note_read", nom: "Consulter les notes" },
|
||||||
|
{ id: "note_write", nom: "Gérer les notes" },
|
||||||
|
{ id: "module_read", nom: "Consulter les modules" },
|
||||||
|
{ id: "module_write", nom: "Gérer les modules" },
|
||||||
|
{ id: "user_read", nom: "Consulter les utilisateurs" },
|
||||||
|
{ id: "user_write", nom: "Gérer les utilisateurs" },
|
||||||
|
{ id: "role_write", nom: "Gérer les rôles" },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const handler: Handlers<null, AuthenticatedState> = {
|
||||||
|
GET(_request, _context): Response {
|
||||||
|
return new Response(JSON.stringify(PERMISSIONS), {
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import { FreshContext, Handlers } from "$fresh/server.ts";
|
|
||||||
import { db } from "$root/databases/db.ts";
|
|
||||||
import { users } from "$root/databases/schema.ts";
|
|
||||||
import { AuthenticatedState } from "$root/defaults/interfaces.ts";
|
|
||||||
import { eq } from "npm:drizzle-orm";
|
|
||||||
|
|
||||||
export const handler: Handlers<null, AuthenticatedState> = {
|
|
||||||
// #60 GET /users
|
|
||||||
async GET(
|
|
||||||
request: Request,
|
|
||||||
_context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
const url = new URL(request.url);
|
|
||||||
const idRole = url.searchParams.get("idRole");
|
|
||||||
|
|
||||||
const rows = idRole
|
|
||||||
? await db.select().from(users).where(eq(users.idRole, Number(idRole)))
|
|
||||||
: await db.select().from(users);
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(rows), {
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// #61 POST /users
|
|
||||||
async POST(
|
|
||||||
request: Request,
|
|
||||||
_context: FreshContext<AuthenticatedState>,
|
|
||||||
): Promise<Response> {
|
|
||||||
const body: { id: string; nom: string; prenom: string; idRole: number } =
|
|
||||||
await request.json();
|
|
||||||
|
|
||||||
if (!body.id || !body.nom || !body.prenom) {
|
|
||||||
return new Response(null, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const existing = await db
|
|
||||||
.select()
|
|
||||||
.from(users)
|
|
||||||
.where(eq(users.id, body.id))
|
|
||||||
.then((rows) => rows[0] ?? null);
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({ error: "Un utilisateur avec cet identifiant existe déjà" }),
|
|
||||||
{ status: 409, headers: { "content-type": "application/json" } },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [created] = await db
|
|
||||||
.insert(users)
|
|
||||||
.values({ id: body.id, nom: body.nom, prenom: body.prenom, idRole: body.idRole })
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(created), {
|
|
||||||
status: 201,
|
|
||||||
headers: { "content-type": "application/json" },
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import makeIndex from "$root/defaults/makeIndex.ts";
|
||||||
|
export default makeIndex(import.meta.dirname!);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import {
|
||||||
|
getPartialsConfig,
|
||||||
|
makePartials,
|
||||||
|
} from "$root/defaults/makePartials.tsx";
|
||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
import { State } from "$root/routes/_middleware.ts";
|
||||||
|
|
||||||
|
export async function Index(request: Request, context: FreshContext<State>) {
|
||||||
|
return <h2>Welcome to Admin.</h2>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = getPartialsConfig();
|
||||||
|
export default makePartials(Index);
|
||||||
Reference in New Issue
Block a user