1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-25 11:43:07 +01:00

Send user and roles id array in GET /guilds/:id/members/:id

This commit is contained in:
Madeline 2023-06-11 00:27:38 +10:00
parent e545edad94
commit 6e47b8e0b3
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
5 changed files with 4273 additions and 34 deletions

View File

@ -7235,6 +7235,55 @@
"$ref": "#/components/schemas/Member"
}
},
"APIPublicMember": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"guild_id": {
"type": "string"
},
"nick": {
"type": "string"
},
"joined_at": {
"type": "string",
"format": "date-time"
},
"pending": {
"type": "boolean"
},
"deaf": {
"type": "boolean"
},
"mute": {
"type": "boolean"
},
"premium_since": {
"type": "integer"
},
"user": {
"$ref": "#/components/schemas/PublicUser"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"deaf",
"guild_id",
"id",
"joined_at",
"mute",
"pending",
"roles",
"user"
]
},
"APIGuildWithJoinedAt": {
"type": "object",
"properties": {
@ -12467,7 +12516,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Member"
"$ref": "#/components/schemas/APIPublicMember"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -34,9 +34,7 @@ const settings = {
noExtraProps: true,
defaultProps: false,
};
const compilerOptions = {
strictNullChecks: true,
};
const Excluded = [
"DefaultSchema",
"Schema",
@ -61,14 +59,6 @@ const Excluded = [
"TransportMakeRequestResponse",
];
function modify(obj) {
for (var k in obj) {
if (typeof obj[k] === "object" && obj[k] !== null) {
modify(obj[k]);
}
}
}
function main() {
const program = TJS.programFromConfig(
path.join(__dirname, "..", "tsconfig.json"),
@ -111,32 +101,12 @@ function main() {
delete part.properties[key];
continue;
}
// if (part.properties[key].anyOf) {
// const nullIndex = part.properties[key].anyOf.findIndex(
// (x) => x.type == "null",
// );
// if (nullIndex != -1) {
// part.properties[key].nullable = true;
// part.properties[key].anyOf.splice(nullIndex, 1);
// if (part.properties[key].anyOf.length == 1) {
// Object.assign(
// part.properties[key],
// part.properties[key].anyOf[0],
// );
// delete part.properties[key].anyOf;
// }
// }
// }
}
}
definitions = { ...definitions, [name]: { ...part } };
}
//modify(definitions);
fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4));
}

View File

@ -27,6 +27,8 @@ import {
handleFile,
Member,
MemberChangeSchema,
PublicMemberProjection,
PublicUserProjection,
Role,
Sticker,
} from "@spacebar/util";
@ -39,7 +41,7 @@ router.get(
route({
responses: {
200: {
body: "Member",
body: "APIPublicMember",
},
403: {
body: "APIErrorResponse",
@ -55,9 +57,28 @@ router.get(
const member = await Member.findOneOrFail({
where: { id: member_id, guild_id },
relations: ["roles", "user"],
select: {
index: true,
// only grab public member props
...Object.fromEntries(
PublicMemberProjection.map((x) => [x, true]),
),
// and public user props
user: Object.fromEntries(
PublicUserProjection.map((x) => [x, true]),
),
roles: {
id: true,
},
},
});
return res.json(member);
return res.json({
...member.toPublicMember(),
user: member.user.toPublicUser(),
roles: member.roles.map((x) => x.id),
});
},
);

View File

@ -11,6 +11,7 @@ import {
Member,
Message,
PrivateUser,
PublicMember,
PublicUser,
Role,
Sticker,
@ -68,6 +69,7 @@ export type APIChannelArray = Channel[];
export type APIEmojiArray = Emoji[];
export type APIMemberArray = Member[];
export type APIPublicMember = PublicMember;
export interface APIGuildWithJoinedAt extends Guild {
joined_at: string;