🎨 formatting files

This commit is contained in:
Flam3rboy
2021-04-25 19:46:57 +02:00
parent 6722c1556c
commit 5dd97905ab
6 changed files with 35 additions and 70 deletions
+18 -36
View File
@@ -1,8 +1,4 @@
import {
Router,
Request,
Response
} from "express";
import { Router, Request, Response } from "express";
import {
ChannelModel,
ChannelCreateEvent,
@@ -10,39 +6,23 @@ import {
UserModel,
toObject,
ChannelType,
Snowflake
Snowflake,
trimSpecial,
} from "@fosscord/server-util";
import {
HTTPError
} from "lambert-server";
import {
emitEvent
} from "../../../util/Event";
import {
getPublicUser
} from "../../../util/User";
import {
DmChannelCreateSchema
} from "../../../schema/Channel";
import {
check
} from "../../../util/instanceOf";
import { HTTPError } from "lambert-server";
import { emitEvent } from "../../../util/Event";
import { getPublicUser } from "../../../util/User";
import { DmChannelCreateSchema } from "../../../schema/Channel";
import { check } from "../../../util/instanceOf";
const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
const user = await UserModel.findOne({
id: req.user_id
}, {
guilds: true
}).exec();
if (!user) throw new HTTPError("User not found", 404);
var testID = "829044530203328513"; //FOR TEST
var channels = await ChannelModel.find({
recipients: req.user_id,
type: 1
$or: [
{ recipients: req.user_id, type: ChannelType.DM },
{ recipients: req.user_id, type: ChannelType.GROUP_DM },
],
}).exec();
res.json(toObject(channels));
@@ -50,20 +30,22 @@ router.get("/", async (req: Request, res: Response) => {
router.post("/", check(DmChannelCreateSchema), async (req, res) => {
const body = req.body as DmChannelCreateSchema;
if (body.recipients.length === 0) throw new HTTPError("You need to specify at least one recipient");
const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM;
const name = trimSpecial(body.name);
const channel = {
...body,
name,
type,
owner_id: req.user_id,
id: Snowflake.generate(),
type: ChannelType.DM,
created_at: new Date(),
};
await new ChannelModel(channel).save();
/*Event({ event: "CHANNEL_CREATE", data: channel } as ChannelCreateEvent);*/
res.json(channel);
});
export default router;
export default router;