Fix GET /users/@me/channels
This commit is contained in:
parent
5fa02e6b10
commit
c4cfa42c60
@ -1,21 +1,12 @@
|
|||||||
import { Request, Response, Router } from "express";
|
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";
|
import { route } from "@fosscord/api";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
const recipients = await Recipient.find({ where: { user_id: req.user_id }, relations: ["channel", "user"] });
|
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]))));
|
||||||
//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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface DmChannelCreateSchema {
|
export interface DmChannelCreateSchema {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user