Add a way to get a user's poll history
This commit is contained in:
parent
6a5503c7a6
commit
cb98228147
1 changed files with 26 additions and 0 deletions
26
server/src/endpoints/polls/list.ts
Normal file
26
server/src/endpoints/polls/list.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Request, ResponseToolkit } from "@hapi/hapi";
|
||||||
|
import { log, twitchAuths } from "~/main";
|
||||||
|
import boom from "@hapi/boom";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
method: `GET`, path: `/twitch/{user}/poll`,
|
||||||
|
options: { auth: false },
|
||||||
|
async handler(request: Request, h: ResponseToolkit): Promise<any> {
|
||||||
|
log.debug(`Listing all Twitch polls`);
|
||||||
|
let user = request.params.user;
|
||||||
|
|
||||||
|
// Assert user existance
|
||||||
|
if (twitchAuths[user] == null) {
|
||||||
|
throw boom.notFound("Invalid user");
|
||||||
|
};
|
||||||
|
|
||||||
|
let auth = twitchAuths[user];
|
||||||
|
|
||||||
|
try {
|
||||||
|
let r = await auth.request<any>("GET", `/polls?broadcaster_id=${auth.bid}`);
|
||||||
|
return h.response(r.data)
|
||||||
|
} catch (err: any) {
|
||||||
|
throw boom.internal(err.response.message);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue