diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-07-12 23:37:52 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-07-12 23:37:52 +0000 |
| commit | 1105b4a41b2a91a24a164c70264b294a80afe97b (patch) | |
| tree | 8b6e695666a3449fa5ff374da16fdff5e7ce738d /packages/open-api/lib/admin.ts | |
| parent | ba7a87fe68e18dca53cb21ebd1ff0bab7e3ab414 (diff) | |
| download | karakeep-1105b4a41b2a91a24a164c70264b294a80afe97b.tar.zst | |
feat(api): Expose the update user API in the openapi specs
Diffstat (limited to '')
| -rw-r--r-- | packages/open-api/lib/admin.ts | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/packages/open-api/lib/admin.ts b/packages/open-api/lib/admin.ts new file mode 100644 index 00000000..80f786f3 --- /dev/null +++ b/packages/open-api/lib/admin.ts @@ -0,0 +1,100 @@ +import { + extendZodWithOpenApi, + OpenAPIRegistry, +} from "@asteasolutions/zod-to-openapi"; +import { z } from "zod"; + +import { updateUserSchema } from "@karakeep/shared/types/admin"; + +import { BearerAuth } from "./common"; + +export const registry = new OpenAPIRegistry(); +extendZodWithOpenApi(z); + +const updateUserRequestSchema = updateUserSchema.omit({ userId: true }); + +const updateUserResponseSchema = z.object({ + success: z.boolean(), +}); + +registry.registerPath({ + method: "put", + path: "/admin/users/{userId}", + description: + "Update a user's role, bookmark quota, or storage quota. Admin access required.", + summary: "Update user", + tags: ["Admin"], + security: [{ [BearerAuth.name]: [] }], + request: { + params: z.object({ + userId: z.string().openapi({ + description: "The ID of the user to update", + example: "user_123", + }), + }), + body: { + content: { + "application/json": { + schema: updateUserRequestSchema.openapi({ + description: "User update data", + example: { + role: "admin", + bookmarkQuota: 1000, + storageQuota: 5000000000, + }, + }), + }, + }, + }, + }, + responses: { + 200: { + description: "User updated successfully", + content: { + "application/json": { + schema: updateUserResponseSchema, + }, + }, + }, + 400: { + description: "Bad request - Invalid input data or cannot update own user", + content: { + "application/json": { + schema: z.object({ + error: z.string(), + }), + }, + }, + }, + 401: { + description: "Unauthorized - Authentication required", + content: { + "application/json": { + schema: z.object({ + error: z.string(), + }), + }, + }, + }, + 403: { + description: "Forbidden - Admin access required", + content: { + "application/json": { + schema: z.object({ + error: z.string(), + }), + }, + }, + }, + 404: { + description: "User not found", + content: { + "application/json": { + schema: z.object({ + error: z.string(), + }), + }, + }, + }, + }, +}); |
