mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-03-30 14:25:37 +00:00
✨ feat: initial prototype
This commit is contained in:
30
apps/backend/src/routes/users.ts
Normal file
30
apps/backend/src/routes/users.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { UpdateUserInput } from "@minikura/db";
|
||||
import { Elysia } from "elysia";
|
||||
import { userService } from "../application/di-container";
|
||||
import { requireAdmin, requireAuth } from "../lib/authorization";
|
||||
|
||||
export const userRoutes = new Elysia({ prefix: "/users" })
|
||||
.use(requireAdmin)
|
||||
.get("/", async () => {
|
||||
const users = await userService.getAllUsers();
|
||||
return users;
|
||||
})
|
||||
|
||||
.use(requireAuth)
|
||||
.get("/:id", async ({ params }) => {
|
||||
const foundUser = await userService.getUserById(params.id);
|
||||
return foundUser;
|
||||
})
|
||||
|
||||
.use(requireAdmin)
|
||||
.patch("/:id", async ({ params, body }) => {
|
||||
const input = body as UpdateUserInput;
|
||||
const updatedUser = await userService.updateUser(params.id, input);
|
||||
return updatedUser;
|
||||
})
|
||||
|
||||
.use(requireAuth)
|
||||
.delete("/:id", async ({ params, user }) => {
|
||||
await userService.deleteUser(user.id, params.id);
|
||||
return { success: true };
|
||||
});
|
||||
Reference in New Issue
Block a user