mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 13:14:06 +01:00
[Route] PATCH /users/:id
This commit is contained in:
parent
ba38a34a83
commit
8d077690d6
@ -1,12 +1,13 @@
|
|||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import { UserModel } from "@fosscord/server-util";
|
import { UserModel, toObject } from "@fosscord/server-util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { getPublicUser } from "../../../util/User";
|
import { getPublicUser } from "../../../util/User";
|
||||||
|
import { UserModifySchema } from "../../../schema/User"
|
||||||
|
import { check } from "../../../util/instanceOf";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
// TODO: user projection
|
|
||||||
const user = await UserModel.findOne({ id: req.user_id }).exec();
|
const user = await UserModel.findOne({ id: req.user_id }).exec();
|
||||||
if (!user) throw new HTTPError("User not found", 404);
|
if (!user) throw new HTTPError("User not found", 404);
|
||||||
|
|
||||||
@ -15,4 +16,17 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
res.json(publicUser);
|
res.json(publicUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => {
|
||||||
|
const body = req.body as UserModifySchema;
|
||||||
|
|
||||||
|
const user = await UserModel.findOne({ id: req.user_id }).exec();
|
||||||
|
if (!user) throw new HTTPError("User not found", 404);
|
||||||
|
|
||||||
|
var newuser = await UserModel.findOneAndUpdate({ id: req.user_id }, {
|
||||||
|
...body
|
||||||
|
}).exec();
|
||||||
|
|
||||||
|
res.json(newuser);
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -41,3 +41,13 @@ export interface UserUpdateSchema {
|
|||||||
public_flags: bigint;
|
public_flags: bigint;
|
||||||
guilds: string[];
|
guilds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const UserModifySchema = {
|
||||||
|
username: String,
|
||||||
|
avatar: String || null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface UserModifySchema {
|
||||||
|
username: string;
|
||||||
|
avatar: string | null;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user