/[sudobot]/trunk/src/api/controllers/InfoController.ts
ViewVC logotype

Annotation of /trunk/src/api/controllers/InfoController.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 369 - (hide annotations)
Mon Jul 29 17:29:49 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 1506 byte(s)
feat(api): add information controller
1 rakin 369 import { dot, object } from "dot-object";
2     import { NextFunction, Response } from "express";
3     import { body } from "express-validator";
4     import KeyValuePair from "../../types/KeyValuePair";
5     import Controller from "../Controller";
6     import RequireAuth from "../middleware/RequireAuth";
7     import ValidatorError from "../middleware/ValidatorError";
8     import Request from "../Request";
9    
10     export default class InfoController extends Controller {
11     globalMiddleware(): Function[] {
12     return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {
13     const { id } = request.params;
14    
15     if (!request.user?.guilds.includes(id)) {
16     return response.status(403).send({ error: "You don't have permission to access information of this guild." });
17     }
18    
19     if (id === "global" || !this.client.config.props[id]) {
20     return response.status(404).send({ error: "No guild found with the given ID" });
21     }
22    
23     next();
24     }];
25     }
26    
27     middleware(): KeyValuePair<Function[]> {
28     return {
29    
30     };
31     }
32    
33     public async indexChannels(request: Request) {
34     const channels = this.client.guilds.cache.get(request.params.id)?.channels.cache;
35    
36     if (request.query?.types) {
37     const types = request.query?.types.toString().split('|');
38     return channels?.filter(channel => types.includes(channel.type));
39     }
40    
41     return channels;
42     }
43     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26