From cb98228147803be565cdc31da069b0cad59f03e0 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 13 Oct 2022 00:24:56 -0600 Subject: [PATCH] Add a way to get a user's poll history --- server/src/endpoints/polls/list.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 server/src/endpoints/polls/list.ts diff --git a/server/src/endpoints/polls/list.ts b/server/src/endpoints/polls/list.ts new file mode 100644 index 0000000..6645f8e --- /dev/null +++ b/server/src/endpoints/polls/list.ts @@ -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 { + 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("GET", `/polls?broadcaster_id=${auth.bid}`); + return h.response(r.data) + } catch (err: any) { + throw boom.internal(err.response.message); + }; + }, +}; \ No newline at end of file