mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { apiRoute, auth, withUserParam } from "@/api";
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
|
import { Role } from "@versia/kit/db";
|
|
|
|
const route = createRoute({
|
|
method: "get",
|
|
path: "/api/v1/accounts/{id}/roles",
|
|
summary: "List user roles",
|
|
middleware: [
|
|
auth({
|
|
auth: false,
|
|
}),
|
|
withUserParam,
|
|
] as const,
|
|
request: {
|
|
params: z.object({
|
|
id: z.string().uuid(),
|
|
}),
|
|
},
|
|
responses: {
|
|
200: {
|
|
description: "List of roles",
|
|
content: {
|
|
"application/json": {
|
|
schema: z.array(Role.schema),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
export default apiRoute((app) => {
|
|
app.openapi(route, async (context) => {
|
|
const targetUser = context.get("user");
|
|
|
|
const roles = await Role.getUserRoles(
|
|
targetUser.id,
|
|
targetUser.data.isAdmin,
|
|
);
|
|
|
|
return context.json(
|
|
roles.map((role) => role.toApi()),
|
|
200,
|
|
);
|
|
});
|
|
});
|