feat: add route to expire a poll

This commit is contained in:
CyberL1
2026-06-25 17:56:49 +02:00
committed by Rory&
parent c440735e4b
commit a12224536e
3 changed files with 50 additions and 0 deletions
Binary file not shown.
@@ -0,0 +1,49 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Request, Response, Router } from "express";
import { route } from "@spacebar/api/util/handlers/route";
import { Message } from "#database";
import { DiscordApiErrors } from "#util";
const router: Router = Router({ mergeParams: true });
router.post("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
const { poll_id } = req.params as { [key: string]: string };
const message = await Message.findOne({ where: { id: poll_id } });
if (!message) {
throw DiscordApiErrors.UNKNOWN_MESSAGE;
}
if (!message.poll) {
throw DiscordApiErrors.NON_POLL_MESSAGE_CANNOT_EXPIRE;
}
if (new Date() > new Date(message.poll.expiry)) {
throw DiscordApiErrors.POLL_EXPIRED;
}
message.poll.expiry = new Date();
await message.save();
res.send(message);
});
export default router;
+1
View File
@@ -663,6 +663,7 @@ export const DiscordApiErrors = {
POLL_EXPIRED: new ApiError("Poll expired", 520001),
POLL_INVALID_CHANNEL_TYPE: new ApiError("Invalid channel type for poll creation", 520002),
POLL_CANNOT_EDIT_MESSAGE: new ApiError("Cannot edit a poll message", 520003),
NON_POLL_MESSAGE_CANNOT_EXPIRE: new ApiError("Cannot expire a non-poll message", 520006),
//Other errors
UNKNOWN_VOICE_STATE: new ApiError("Unknown Voice State", 10065, 404),