🐛 [Member] list fix to also return user
This commit is contained in:
parent
01eb91a63e
commit
5c11bf1b87
4
package-lock.json
generated
4
package-lock.json
generated
@ -1363,7 +1363,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/fosscord-server-util": {
|
"node_modules/fosscord-server-util": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#92a6c981ce12f4484509d0388cb1fba2a52b55c4",
|
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#371a56859695321bfa862a1c66d27279018cc864",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
@ -5077,7 +5077,7 @@
|
|||||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
||||||
},
|
},
|
||||||
"fosscord-server-util": {
|
"fosscord-server-util": {
|
||||||
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#92a6c981ce12f4484509d0388cb1fba2a52b55c4",
|
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#371a56859695321bfa862a1c66d27279018cc864",
|
||||||
"from": "fosscord-server-util@github:fosscord/fosscord-server-util",
|
"from": "fosscord-server-util@github:fosscord/fosscord-server-util",
|
||||||
"requires": {
|
"requires": {
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
@ -3,6 +3,7 @@ import { GuildModel, MemberModel } from "fosscord-server-util";
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { instanceOf, Length } from "../../../../../../util/instanceOf";
|
import { instanceOf, Length } from "../../../../../../util/instanceOf";
|
||||||
import { PublicMemberProjection } from "../../../../../../util/Member";
|
import { PublicMemberProjection } from "../../../../../../util/Member";
|
||||||
|
import { PublicUserProjection } from "../../../../../../util/User";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
var members = await MemberModel.find({ guild_id, ...query }, PublicMemberProjection)
|
var members = await MemberModel.find({ guild_id, ...query }, PublicMemberProjection)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.populate("user")
|
.populate({ path: "user", select: PublicUserProjection })
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
return res.json(members);
|
return res.json(members);
|
||||||
@ -40,9 +41,10 @@ router.get("/:member", async (req: Request, res: Response) => {
|
|||||||
const guild_id = BigInt(req.params.id);
|
const guild_id = BigInt(req.params.id);
|
||||||
const user_id = BigInt(req.params.member);
|
const user_id = BigInt(req.params.member);
|
||||||
|
|
||||||
const member = await MemberModel.findOne({ id: user_id, guild_id }).populate("user").exec();
|
const member = await MemberModel.findOne({ id: user_id, guild_id })
|
||||||
|
.populate({ path: "user", select: PublicUserProjection })
|
||||||
|
.exec();
|
||||||
if (!member) throw new HTTPError("Member not found", 404);
|
if (!member) throw new HTTPError("Member not found", 404);
|
||||||
console.log(member.user);
|
|
||||||
|
|
||||||
return res.json(member);
|
return res.json(member);
|
||||||
});
|
});
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import { UserModel } from "fosscord-server-util";
|
import { UserModel } from "fosscord-server-util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
export async function getPublicUser(user_id: bigint, additional_fields?: any) {
|
export const PublicUserProjection = {
|
||||||
const user = await UserModel.findOne(
|
|
||||||
{ id: user_id },
|
|
||||||
{
|
|
||||||
username: true,
|
username: true,
|
||||||
discriminator: true,
|
discriminator: true,
|
||||||
id: true,
|
id: true,
|
||||||
public_flags: true,
|
public_flags: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getPublicUser(user_id: bigint, additional_fields?: any) {
|
||||||
|
const user = await UserModel.findOne(
|
||||||
|
{ id: user_id },
|
||||||
|
{
|
||||||
|
...PublicUserProjection,
|
||||||
...additional_fields,
|
...additional_fields,
|
||||||
}
|
}
|
||||||
).exec();
|
).exec();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user