Add an endpoint for viewing the guild bracket data through a GET request
This commit is contained in:
parent
53a6e7f350
commit
b2e121aa8e
3 changed files with 43 additions and 7 deletions
33
src/endpoints/management/view_bracket_data.ts
Normal file
33
src/endpoints/management/view_bracket_data.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { Request, ResponseToolkit } from "@hapi/hapi";
|
||||
import { DISCORD_API_URI } from "@/constants";
|
||||
import { config, db } from "@/main";
|
||||
import axios from "axios";
|
||||
|
||||
export default {
|
||||
method: `GET`, path: `/{guild_id}/bracket`,
|
||||
async handler(request: Request, h: ResponseToolkit) {
|
||||
let { guild_id: gID } = request.params;
|
||||
let { convert_ids } = request.query;
|
||||
|
||||
// See if we are adding the user's conversion table to the response
|
||||
let users: {[index: string]: string} = {};
|
||||
if (convert_ids.toLowerCase() === `true` && config.guilds[gID].bot_token) {
|
||||
for (var k in db[gID].bracket.users) {
|
||||
let r = await axios.get(
|
||||
`${DISCORD_API_URI}/users/${k}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${config.guilds[gID].bot_token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
users[k] = `${r.data.username}#${r.data.discriminator}`
|
||||
};
|
||||
};
|
||||
|
||||
return h.response({
|
||||
db: db[gID].bracket,
|
||||
user_conversion: users
|
||||
});
|
||||
},
|
||||
}
|
||||
1
src/types/config.d.ts
vendored
1
src/types/config.d.ts
vendored
|
|
@ -2,6 +2,7 @@ interface channel_config {
|
|||
password: string;
|
||||
api_base: string;
|
||||
quote_max: number;
|
||||
bot_token?: string;
|
||||
delete_mode: "remove_components" | "delete_message";
|
||||
params: { [index: string]: any };
|
||||
}
|
||||
|
|
|
|||
16
src/types/database.d.ts
vendored
16
src/types/database.d.ts
vendored
|
|
@ -1,16 +1,18 @@
|
|||
interface bracket_data {
|
||||
msg: string;
|
||||
channel: string;
|
||||
quotes: string[];
|
||||
votes: { [index: number]: number };
|
||||
users: { [index: string]: number };
|
||||
}
|
||||
|
||||
interface database {
|
||||
[index: string]: {
|
||||
webhook: {
|
||||
id: string;
|
||||
token: string;
|
||||
};
|
||||
bracket: {
|
||||
msg: string;
|
||||
channel: string;
|
||||
quotes: string[];
|
||||
votes: { [index: number]: number };
|
||||
users: { [index: string]: number };
|
||||
};
|
||||
bracket: bracket_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue