diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-12 23:28:56 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-12 23:28:56 +0200 |
commit | 0b5534bc4144d6c708b19b1890b73eb56016e123 (patch) | |
tree | 4f17716499b03ba7ee395a7ab6f90df97a41ea46 /api/src/routes/users/@me/index.ts | |
parent | :construction: :sparkles: new body parser (bans route) (diff) | |
download | server-0b5534bc4144d6c708b19b1890b73eb56016e123.tar.xz |
:sparkles: #307 done
Diffstat (limited to 'api/src/routes/users/@me/index.ts')
-rw-r--r-- | api/src/routes/users/@me/index.ts | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts index 451a657c..68723374 100644 --- a/api/src/routes/users/@me/index.ts +++ b/api/src/routes/users/@me/index.ts @@ -1,16 +1,33 @@ import { Router, Request, Response } from "express"; import { User, PrivateUserProjection } from "@fosscord/util"; -import { UserModifySchema } from "../../../schema/User"; -import { check } from "@fosscord/api"; +import { check, route } from "@fosscord/api"; import { handleFile } from "@fosscord/api"; const router: Router = Router(); +export interface UserModifySchema { + /** + * @minLength 1 + * @maxLength 100 + */ + username?: string; + avatar?: string | null; + /** + * @maxLength 1024 + */ + bio?: string; + accent_color?: number | null; + banner?: string | null; + password?: string; + new_password?: string; + code?: string; +} + router.get("/", async (req: Request, res: Response) => { - res.json(await User.getPublicUser(req.user_id, { select: PrivateUserProjection })); + res.json(await User.findOne({ select: PrivateUserProjection, where: { id: req.user_id } })); }); -router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => { +router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res: Response) => { const body = req.body as UserModifySchema; if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string); |