diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-03-11 20:09:32 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-03-11 20:09:32 +0000 |
| commit | b8c587e3c3e717263da84522d59c7904715ae22a (patch) | |
| tree | a26a67162118b4a629d33a833dd25be67d344855 /packages/open-api/lib/users.ts | |
| parent | 59c444a503c0124988608c190342acc53c797107 (diff) | |
| download | karakeep-b8c587e3c3e717263da84522d59c7904715ae22a.tar.zst | |
feat: Add endpoints for whoami and user stats. Fixes #1113
Diffstat (limited to 'packages/open-api/lib/users.ts')
| -rw-r--r-- | packages/open-api/lib/users.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/open-api/lib/users.ts b/packages/open-api/lib/users.ts new file mode 100644 index 00000000..657fcdc8 --- /dev/null +++ b/packages/open-api/lib/users.ts @@ -0,0 +1,55 @@ +import { + extendZodWithOpenApi, + OpenAPIRegistry, +} from "@asteasolutions/zod-to-openapi"; +import { z } from "zod"; + +import { + zUserStatsResponseSchema, + zWhoAmIResponseSchema, +} from "@hoarder/shared/types/users"; + +import { BearerAuth } from "./common"; + +export const registry = new OpenAPIRegistry(); +extendZodWithOpenApi(z); + +registry.registerPath({ + method: "get", + path: "/users/me", + description: "Returns info about the current user", + summary: "Get current user info", + tags: ["Users"], + security: [{ [BearerAuth.name]: [] }], + request: {}, + responses: { + 200: { + description: "Object with user data.", + content: { + "application/json": { + schema: zWhoAmIResponseSchema, + }, + }, + }, + }, +}); + +registry.registerPath({ + method: "get", + path: "/users/me/stats", + description: "Returns stats about the current user", + summary: "Get current user stats", + tags: ["Users"], + security: [{ [BearerAuth.name]: [] }], + request: {}, + responses: { + 200: { + description: "Object with user stats.", + content: { + "application/json": { + schema: zUserStatsResponseSchema, + }, + }, + }, + }, +}); |
