oapi: invites
This commit is contained in:
parent
5c0a6f4e55
commit
3a40254ca5
@ -7779,8 +7779,35 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"default": {
|
"200": {
|
||||||
"description": "No description available"
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Invite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/APIErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/APIErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
@ -16,22 +16,34 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
emitEvent,
|
emitEvent,
|
||||||
getPermission,
|
getPermission,
|
||||||
Guild,
|
Guild,
|
||||||
Invite,
|
Invite,
|
||||||
InviteDeleteEvent,
|
InviteDeleteEvent,
|
||||||
User,
|
|
||||||
PublicInviteRelation,
|
PublicInviteRelation,
|
||||||
|
User,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/:code", route({}), async (req: Request, res: Response) => {
|
router.get(
|
||||||
|
"/:code",
|
||||||
|
route({
|
||||||
|
responses: {
|
||||||
|
"200": {
|
||||||
|
body: "Invite",
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
|
|
||||||
const invite = await Invite.findOneOrFail({
|
const invite = await Invite.findOneOrFail({
|
||||||
@ -40,11 +52,28 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).send(invite);
|
res.status(200).send(invite);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/:code",
|
"/:code",
|
||||||
route({ right: "USE_MASS_INVITES" }),
|
route({
|
||||||
|
right: "USE_MASS_INVITES",
|
||||||
|
responses: {
|
||||||
|
"200": {
|
||||||
|
body: "Invite",
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
const { guild_id } = await Invite.findOneOrFail({
|
const { guild_id } = await Invite.findOneOrFail({
|
||||||
@ -75,14 +104,36 @@ router.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// * cant use permission of route() function because path doesn't have guild_id/channel_id
|
// * cant use permission of route() function because path doesn't have guild_id/channel_id
|
||||||
router.delete("/:code", route({}), async (req: Request, res: Response) => {
|
router.delete(
|
||||||
|
"/:code",
|
||||||
|
route({
|
||||||
|
responses: {
|
||||||
|
"200": {
|
||||||
|
body: "Invite",
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
body: "APIErrorResponse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response) => {
|
||||||
const { code } = req.params;
|
const { code } = req.params;
|
||||||
const invite = await Invite.findOneOrFail({ where: { code } });
|
const invite = await Invite.findOneOrFail({ where: { code } });
|
||||||
const { guild_id, channel_id } = invite;
|
const { guild_id, channel_id } = invite;
|
||||||
|
|
||||||
const permission = await getPermission(req.user_id, guild_id, channel_id);
|
const permission = await getPermission(
|
||||||
|
req.user_id,
|
||||||
|
guild_id,
|
||||||
|
channel_id,
|
||||||
|
);
|
||||||
|
|
||||||
if (!permission.has("MANAGE_GUILD") && !permission.has("MANAGE_CHANNELS"))
|
if (
|
||||||
|
!permission.has("MANAGE_GUILD") &&
|
||||||
|
!permission.has("MANAGE_CHANNELS")
|
||||||
|
)
|
||||||
throw new HTTPError(
|
throw new HTTPError(
|
||||||
"You missing the MANAGE_GUILD or MANAGE_CHANNELS permission",
|
"You missing the MANAGE_GUILD or MANAGE_CHANNELS permission",
|
||||||
401,
|
401,
|
||||||
@ -102,6 +153,7 @@ router.delete("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
res.json({ invite: invite });
|
res.json({ invite: invite });
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user