timers should not be used on issues with multiple assignees

This commit is contained in:
Oliver Bryan
2026-01-20 23:13:12 +00:00
parent 6a91b4b9f3
commit 42a537a967
6 changed files with 53 additions and 10 deletions

View File

@@ -182,3 +182,11 @@ export async function getIssuesWithUsersByProject(projectId: number): Promise<Is
Assignees: assigneesByIssue.get(row.Issue.id) || [],
}));
}
export async function getIssueAssigneeCount(issueId: number): Promise<number> {
const [result] = await db
.select({ count: sql<number>`COUNT(*)` })
.from(IssueAssignee)
.where(eq(IssueAssignee.issueId, issueId));
return result?.count ?? 0;
}

View File

@@ -5,7 +5,12 @@ import {
TimerToggleRequestSchema,
} from "@sprint/shared";
import type { AuthedRequest } from "../../auth/middleware";
import { appendTimestamp, createTimedSession, getActiveTimedSession } from "../../db/queries";
import {
appendTimestamp,
createTimedSession,
getActiveTimedSession,
getIssueAssigneeCount,
} from "../../db/queries";
import { parseJsonBody } from "../../validation";
export default async function timerToggle(req: AuthedRequest) {
@@ -14,6 +19,14 @@ export default async function timerToggle(req: AuthedRequest) {
const { issueId } = parsed.data;
const assigneeCount = await getIssueAssigneeCount(issueId);
if (assigneeCount > 1) {
return Response.json(
{ error: "Timers cannot be used on issues with multiple assignees", code: "MULTIPLE_ASSIGNEES" },
{ status: 400 },
);
}
const activeSession = await getActiveTimedSession(req.userId, issueId);
if (!activeSession) {