Skip to content

Commit

Permalink
admin api: list guild bans
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Dec 3, 2023
1 parent 296c257 commit dba9906
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
72 changes: 72 additions & 0 deletions src/api/routes/admin/guilds/#guild_id/bans/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { route } from "@spacebar/api";
import { Ban } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { MoreThan } from "typeorm";
const router = Router();

router.get(
"/",
route({
description: "Get bans of a guild",
right: "MANAGE_GUILDS",
query: {
limit: {
type: "number",
description:
"max number of bans to return (1-1000). default 100",
},
after: {
type: "string",
},
},
responses: {
200: {
body: "GuildBansResponse",
},
400: {
body: "APIErrorResponse",
},
404: {
body: "APIErrorResponse",
},
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { after } = req.query as {
after?: string;
};
const limit = Number(req.query.limit) || 100;
if (limit > 1000 || limit < 1)
throw new HTTPError("Limit must be between 1 and 1000");

const bans = await Ban.find({
where: { guild_id, ...(after ? { id: MoreThan(after) } : {}) },
order: { id: "ASC" },
take: limit,
});

return res.json(bans);
},
);

export default router;
6 changes: 3 additions & 3 deletions src/api/routes/admin/guilds/#guild_id/members/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { route } from "@spacebar/api";
import { Member } from "@spacebar/util";
import { Member, PublicMemberProjection } from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { MoreThan } from "typeorm";
Expand All @@ -32,7 +32,7 @@ router.get(
limit: {
type: "number",
description:
"max number of members to return (1-1000). default 1",
"max number of members to return (1-1000). default 100",
},
after: {
type: "string",
Expand Down Expand Up @@ -61,7 +61,7 @@ router.get(

const members = await Member.find({
where: { guild_id, ...(after ? { id: MoreThan(after) } : {}) },
// select: PublicMemberProjection,
select: PublicMemberProjection, // TODO: Add admin projection
order: { id: "ASC" },
take: limit,
});
Expand Down
3 changes: 2 additions & 1 deletion src/api/routes/admin/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ router.get(
description: "Get a list of users",
query: {
limit: {
description: "The maximum amount of users to return",
description:
"max number of users to return (1-1000). default 100",
type: "number",
required: false,
},
Expand Down

0 comments on commit dba9906

Please sign in to comment.