[backend/api] Fix API errors on poll vote

This commit is contained in:
Laura Hausmann 2025-02-22 23:17:54 +01:00
parent d33e2d7bcc
commit 9d480e3fba
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -515,15 +515,14 @@ public class NoteController(
throw GracefulException.BadRequest("At least one vote must be included");
var target = await db.Notes
.Where(p => p.Id == id)
.EnsureVisibleFor(user)
.IncludeCommonProperties()
.Include(p => p.Poll)
.Where(p => p.Id == id && p.Poll != null)
.EnsureVisibleFor(user)
.FirstOrDefaultAsync()
?? throw GracefulException.NotFound("Note not found");
if (target.Poll == null)
throw GracefulException.NotFound("Poll not found");
?? throw GracefulException.NotFound("Poll not found");
if (target.Poll.ExpiresAt != null && target.Poll.ExpiresAt < DateTime.UtcNow)
if (target.Poll!.ExpiresAt != null && target.Poll.ExpiresAt < DateTime.UtcNow)
throw GracefulException.NotFound("Poll has expired");
var voted = await db.PollVotes