diff options
author | AlTech98 <altech123159@gmail.com> | 2021-09-17 13:59:21 +0200 |
---|---|---|
committer | AlTech98 <altech123159@gmail.com> | 2021-09-17 13:59:21 +0200 |
commit | 7cbb45f979b8e4f01b1028dede05046a3a6a9858 (patch) | |
tree | 7be97d155a204bbeab4f4075e0f654db298e1fe6 /api/src | |
parent | Update ChannelService.ts (diff) | |
download | server-7cbb45f979b8e4f01b1028dede05046a3a6a9858.tar.xz |
Fix GET /users/@me/channels
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/routes/users/@me/channels.ts | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/api/src/routes/users/@me/channels.ts b/api/src/routes/users/@me/channels.ts index bd7af18c..873ff245 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/api/src/routes/users/@me/channels.ts @@ -1,21 +1,12 @@ import { Request, Response, Router } from "express"; -import { PublicUserProjection, Recipient, User, ChannelService } from "@fosscord/util"; +import { Recipient, ChannelService, DmChannelDTO } from "@fosscord/util"; import { route } from "@fosscord/api"; const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const recipients = await Recipient.find({ where: { user_id: req.user_id }, relations: ["channel", "user"] }); - - //TODO check if this is right - const aa = await Promise.all(recipients.map(async (x) => { - return { - ...(x.channel), - recipients: await User.findOneOrFail({ where: { id: x.user_id }, select: PublicUserProjection }), - } - })) - - res.json(aa); + const recipients = await Recipient.find({ where: { user_id: req.user_id, closed: false }, relations: ["channel", "channel.recipients"] }); + res.json(await Promise.all(recipients.map(r => DmChannelDTO.from(r.channel, [req.user_id])))); }); export interface DmChannelCreateSchema { |