1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 10:52:31 +01:00

Mutual Guilds (#637)

This commit is contained in:
RealMANI 2022-02-16 11:15:54 +03:30 committed by GitHub
parent e8b24b3684
commit 76d5d83dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { Router, Request, Response } from "express";
import { PublicConnectedAccount, PublicUser, User, UserPublic } from "@fosscord/util";
import { PublicConnectedAccount, PublicUser, User, UserPublic, Member } from "@fosscord/util";
import { route } from "@fosscord/api";
const router: Router = Router();
@ -15,11 +15,24 @@ router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }),
if (req.params.id === "@me") req.params.id = req.user_id;
const user = await User.getPublicUser(req.params.id, { relations: ["connected_accounts"] });
var mutual_guilds: object[] = [];
const requested_member = await Member.find( { id: req.params.id, })
const self_member = await Member.find( { id: req.user_id, })
for(const rmem of requested_member) {
for(const smem of self_member) {
if (smem.guild_id === rmem.guild_id) {
mutual_guilds.push({id: rmem.guild_id, nick: rmem.nick})
}
}
}
res.json({
connected_accounts: user.connected_accounts,
premium_guild_since: null, // TODO
premium_since: null, // TODO
mutual_guilds: [], // TODO {id: "", nick: null} when ?with_mutual_guilds=true
mutual_guilds: mutual_guilds, // TODO {id: "", nick: null} when ?with_mutual_guilds=true
user: {
username: user.username,
discriminator: user.discriminator,