mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 1s
Build Docker Images / lint (push) Failing after 7s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 6s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 1s
Test Publish / build (client) (push) Failing after 0s
Test Publish / build (sdk) (push) Failing after 0s
139 lines
4.5 KiB
TypeScript
139 lines
4.5 KiB
TypeScript
import { z } from "zod";
|
|
import { Id } from "./common.ts";
|
|
import { CustomEmoji } from "./emoji.ts";
|
|
|
|
export const PollOption = z
|
|
.object({
|
|
title: z
|
|
.string()
|
|
.trim()
|
|
.min(1)
|
|
.openapi({
|
|
description: "The text value of the poll option.",
|
|
example: "yes",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#Option-title",
|
|
},
|
|
}),
|
|
votes_count: z
|
|
.number()
|
|
.int()
|
|
.nonnegative()
|
|
.nullable()
|
|
.openapi({
|
|
description:
|
|
"The total number of received votes for this option.",
|
|
example: 6,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#Option-votes_count",
|
|
},
|
|
}),
|
|
})
|
|
.openapi({
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#Option",
|
|
},
|
|
ref: "PollOption",
|
|
});
|
|
|
|
export const Poll = z
|
|
.object({
|
|
id: Id.openapi({
|
|
description: "ID of the poll in the database.",
|
|
example: "d87d230f-e401-4282-80c7-2044ab989662",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#id",
|
|
},
|
|
}),
|
|
expires_at: z
|
|
.string()
|
|
.datetime()
|
|
.nullable()
|
|
.openapi({
|
|
description: "When the poll ends.",
|
|
example: "2025-01-07T14:11:00.000Z",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#expires_at",
|
|
},
|
|
}),
|
|
expired: z.boolean().openapi({
|
|
description: "Is the poll currently expired?",
|
|
example: false,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#expired",
|
|
},
|
|
}),
|
|
multiple: z.boolean().openapi({
|
|
description: "Does the poll allow multiple-choice answers?",
|
|
example: false,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#multiple",
|
|
},
|
|
}),
|
|
votes_count: z
|
|
.number()
|
|
.int()
|
|
.nonnegative()
|
|
.openapi({
|
|
description: "How many votes have been received.",
|
|
example: 6,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#votes_count",
|
|
},
|
|
}),
|
|
voters_count: z
|
|
.number()
|
|
.int()
|
|
.nonnegative()
|
|
.nullable()
|
|
.openapi({
|
|
description:
|
|
"How many unique accounts have voted on a multiple-choice poll.",
|
|
example: 3,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#voters_count",
|
|
},
|
|
}),
|
|
options: z.array(PollOption).openapi({
|
|
description: "Possible answers for the poll.",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#options",
|
|
},
|
|
}),
|
|
emojis: z.array(CustomEmoji).openapi({
|
|
description: "Custom emoji to be used for rendering poll options.",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#emojis",
|
|
},
|
|
}),
|
|
voted: z
|
|
.boolean()
|
|
.optional()
|
|
.openapi({
|
|
description:
|
|
"When called with a user token, has the authorized user voted?",
|
|
example: true,
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#voted",
|
|
},
|
|
}),
|
|
own_votes: z
|
|
.array(z.number().int())
|
|
.optional()
|
|
.openapi({
|
|
description:
|
|
"When called with a user token, which options has the authorized user chosen? Contains an array of index values for options.",
|
|
example: [0],
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll/#own_votes",
|
|
},
|
|
}),
|
|
})
|
|
.openapi({
|
|
description: "Represents a poll attached to a status.",
|
|
externalDocs: {
|
|
url: "https://docs.joinmastodon.org/entities/Poll",
|
|
},
|
|
ref: "Poll",
|
|
});
|