diff --git a/assets/openapi.json b/assets/openapi.json index 5de9ed291..f9f6f540b 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/src/api/routes/channels/#channel_id/polls/#poll_id/expire.ts b/src/api/routes/channels/#channel_id/polls/#poll_id/expire.ts new file mode 100644 index 000000000..9ac128861 --- /dev/null +++ b/src/api/routes/channels/#channel_id/polls/#poll_id/expire.ts @@ -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 . +*/ + +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; diff --git a/src/util/util/Constants.ts b/src/util/util/Constants.ts index b605d1a9e..78c738974 100644 --- a/src/util/util/Constants.ts +++ b/src/util/util/Constants.ts @@ -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),