Move schemas to /src/util/schemas
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { Recipient, DmChannelDTO, Channel } from "@fosscord/util";
|
||||
import { Recipient, DmChannelDTO, Channel, DmChannelCreateSchema } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router: Router = Router();
|
||||
@@ -12,11 +12,6 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
res.json(await Promise.all(recipients.map((r) => DmChannelDTO.from(r.channel, [req.user_id]))));
|
||||
});
|
||||
|
||||
export interface DmChannelCreateSchema {
|
||||
name?: string;
|
||||
recipients: string[];
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
|
||||
const body = req.body as DmChannelCreateSchema;
|
||||
res.json(await Channel.createDMChannel(body.recipients, req.user_id, body.name));
|
||||
|
||||
@@ -1,31 +1,11 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { User, PrivateUserProjection, emitEvent, UserUpdateEvent, handleFile, FieldErrors, adjustEmail, Config } from "@fosscord/util";
|
||||
import { User, PrivateUserProjection, emitEvent, UserUpdateEvent, handleFile, FieldErrors, adjustEmail, Config, UserModifySchema } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import bcrypt from "bcrypt";
|
||||
import { HTTPError } from "lambert-server";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
export interface UserModifySchema {
|
||||
/**
|
||||
* @minLength 1
|
||||
* @maxLength 100
|
||||
*/
|
||||
username?: string;
|
||||
avatar?: string | null;
|
||||
/**
|
||||
* @maxLength 1024
|
||||
*/
|
||||
bio?: string;
|
||||
accent_color?: number;
|
||||
banner?: string | null;
|
||||
password?: string;
|
||||
new_password?: string;
|
||||
code?: string;
|
||||
email?: string;
|
||||
discriminator?: string;
|
||||
}
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
res.json(await User.findOne({ select: PrivateUserProjection, where: { id: req.user_id } }));
|
||||
});
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { BackupCode, generateMfaBackupCodes, User } from "@fosscord/util";
|
||||
import { BackupCode, generateMfaBackupCodes, User, CodesVerificationSchema } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
export interface CodesVerificationSchema {
|
||||
key: string;
|
||||
nonce: string;
|
||||
regenerate?: boolean;
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "CodesVerificationSchema" }), async (req: Request, res: Response) => {
|
||||
const { key, nonce, regenerate } = req.body as CodesVerificationSchema;
|
||||
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { BackupCode, FieldErrors, generateMfaBackupCodes, User } from "@fosscord/util";
|
||||
import { BackupCode, FieldErrors, generateMfaBackupCodes, User, MfaCodesSchema } from "@fosscord/util";
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
const router = Router();
|
||||
|
||||
export interface MfaCodesSchema {
|
||||
password: string;
|
||||
regenerate?: boolean;
|
||||
}
|
||||
|
||||
// TODO: This route is replaced with users/@me/mfa/codes-verification in newer clients
|
||||
|
||||
router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Response) => {
|
||||
|
||||
@@ -2,14 +2,10 @@ import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { verifyToken } from 'node-2fa';
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { User, generateToken, BackupCode } from "@fosscord/util";
|
||||
import { User, generateToken, BackupCode, TotpDisableSchema } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
export interface TotpDisableSchema {
|
||||
code: string;
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res: Response) => {
|
||||
const body = req.body as TotpDisableSchema;
|
||||
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { User, generateToken, BackupCode, generateMfaBackupCodes } from "@fosscord/util";
|
||||
import { User, generateToken, generateMfaBackupCodes, TotpEnableSchema } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import bcrypt from "bcrypt";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { verifyToken } from 'node-2fa';
|
||||
import crypto from "crypto";
|
||||
|
||||
const router = Router();
|
||||
|
||||
export interface TotpEnableSchema {
|
||||
password: string;
|
||||
code?: string;
|
||||
secret?: string;
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "TotpEnableSchema" }), async (req: Request, res: Response) => {
|
||||
const body = req.body as TotpEnableSchema;
|
||||
|
||||
|
||||
@@ -37,10 +37,6 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
return res.json(related_users);
|
||||
});
|
||||
|
||||
export interface RelationshipPutSchema {
|
||||
type?: RelationshipType;
|
||||
}
|
||||
|
||||
router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request, res: Response) => {
|
||||
return await updateRelationship(
|
||||
req,
|
||||
@@ -50,11 +46,6 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request
|
||||
);
|
||||
});
|
||||
|
||||
export interface RelationshipPostSchema {
|
||||
discriminator: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "RelationshipPostSchema" }), async (req: Request, res: Response) => {
|
||||
return await updateRelationship(
|
||||
req,
|
||||
|
||||
Reference in New Issue
Block a user