summary refs log tree commit diff
path: root/api/src/routes/users/@me/channels.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:04 +0200
commitef4d4a318176c3e572adc17427a8b8c728a618ab (patch)
treed95fedbf18b7b7438613b08b72eb30fa5fca8921 /api/src/routes/users/@me/channels.ts
parent:sparkles: typeorm entities (diff)
downloadserver-ef4d4a318176c3e572adc17427a8b8c728a618ab.tar.xz
:construction: api
Diffstat (limited to 'api/src/routes/users/@me/channels.ts')
-rw-r--r--api/src/routes/users/@me/channels.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts

index db9f8832..28e77dd9 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/api/src/routes/users/@me/channels.ts
@@ -1,6 +1,6 @@ import { Router, Request, Response } from "express"; import { - ChannelModel, + Channel, ChannelCreateEvent, toObject, ChannelType, @@ -8,7 +8,7 @@ import { trimSpecial, Channel, DMChannel, - UserModel, + User, emitEvent } from "@fosscord/util"; import { HTTPError } from "lambert-server"; @@ -19,9 +19,9 @@ import { check } from "../../../util/instanceOf"; const router: Router = Router(); router.get("/", async (req: Request, res: Response) => { - var channels = await ChannelModel.find({ recipient_ids: req.user_id }).exec(); + var channels = await Channel.find({ recipient_ids: req.user_id }); - res.json(toObject(channels)); + res.json(channels); }); router.post("/", check(DmChannelCreateSchema), async (req: Request, res: Response) => { @@ -29,14 +29,14 @@ router.post("/", check(DmChannelCreateSchema), async (req: Request, res: Respons body.recipients = body.recipients.filter((x) => x !== req.user_id).unique(); - if (!(await Promise.all(body.recipients.map((x) => UserModel.exists({ id: x })))).every((x) => x)) { + if (!(await Promise.all(body.recipients.map((x) => User.exists({ id: x })))).every((x) => x)) { throw new HTTPError("Recipient not found"); } const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM; const name = trimSpecial(body.name); - const channel = await new ChannelModel({ + const channel = await new Channel({ name, type, owner_id: req.user_id, @@ -46,9 +46,9 @@ router.post("/", check(DmChannelCreateSchema), async (req: Request, res: Respons recipient_ids: [...body.recipients, req.user_id] }).save(); - await emitEvent({ event: "CHANNEL_CREATE", data: toObject(channel), user_id: req.user_id } as ChannelCreateEvent); + await emitEvent({ event: "CHANNEL_CREATE", data: channel), user_id: req.user_id } as ChannelCreateEvent; - res.json(toObject(channel)); + res.json(channel); }); export default router;