Refactor & unit tests

This commit is contained in:
jd
2026-02-13 22:06:49 +00:00
parent eca7405974
commit 387a9a36f3
20 changed files with 423 additions and 148 deletions

27
src/index.ts Normal file
View File

@@ -0,0 +1,27 @@
import {unwrapMethod, guard} from './utilities/guard.ts';
import auth from "./endpoints/auth.ts";
import user from "./endpoints/user.ts";
const server = Bun.serve({
routes: {
"/api/auth/login": {
POST: unwrapMethod(auth.login),
},
"/api/auth/test": {
GET: guard(auth.test, ['ADMIN', 'USERS_OTHER_DELETE'])
},
"/api/user": {
POST: guard(user.create, ['ADMIN', 'USERS_CREATE'])
},
"/api/user/:id": {
GET: guard(user.get, ['ADMIN', 'USERS_OTHERS_READ', 'USERS_SELF_READ'])
},
},
// (optional) fallback for unmatched routes:
fetch(request: Request): Response {
return Response.json({message: "Not found"}, {status: 404});
},
});
console.log(`Server running at ${server.url}`);