( vote: boolean, item: ItemWrapper, versionIdx: number )
| 36 | } |
| 37 | |
| 38 | export async function voteRequest( |
| 39 | vote: boolean, |
| 40 | item: ItemWrapper, |
| 41 | versionIdx: number |
| 42 | ) { |
| 43 | const r = await fetch(`${API_HOST}/vote`, { |
| 44 | method: 'POST', |
| 45 | headers: { |
| 46 | 'Content-Type': 'application/json' |
| 47 | }, |
| 48 | body: JSON.stringify({ |
| 49 | prompt: item.prompt(versionIdx), |
| 50 | html: item.pureHTML(versionIdx), |
| 51 | name: item.name, |
| 52 | emoji: item.emoji, |
| 53 | vote |
| 54 | }) |
| 55 | }) |
| 56 | if (r.status !== 201) { |
| 57 | const body = (await r.json()) as ErrorBody |
| 58 | throw new Error(body.error.message) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | export async function getShare(id: string): Promise<HistoryItem> { |
| 63 | const r = await fetch(`${API_HOST}/share/${id}`) |
no test coverage detected