Files
ncd-fe/packages/pl-api/lib/client/polls.ts
nicole mikołajczyk d5d453e645 pl-api: allow importing parts of the client
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
2026-02-23 10:39:26 +01:00

35 lines
879 B
TypeScript

import * as v from 'valibot';
import { pollSchema } from '../entities';
import type { PlApiBaseClient } from '../client-base';
const polls = (client: PlApiBaseClient) => ({
/**
* View a poll
* View a poll attached to a status.
* @see {@link https://docs.joinmastodon.org/methods/polls/#get}
*/
getPoll: async (pollId: string) => {
const response = await client.request(`/api/v1/polls/${pollId}`);
return v.parse(pollSchema, response.json);
},
/**
* Vote on a poll
* Vote on a poll attached to a status.
* @see {@link https://docs.joinmastodon.org/methods/polls/#vote}
*/
vote: async (pollId: string, choices: number[]) => {
const response = await client.request(`/api/v1/polls/${pollId}/votes`, {
method: 'POST',
body: { choices },
});
return v.parse(pollSchema, response.json);
},
});
export { polls };