prevent overlapping sprints

This commit is contained in:
Oliver Bryan
2026-01-17 02:46:49 +00:00
parent f3523a9a83
commit 0dcfe1b66b
2 changed files with 34 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import { Sprint } from "@sprint/shared";
import { eq } from "drizzle-orm";
import { and, eq, gte, lte } from "drizzle-orm";
import { db } from "../client";
export async function createSprint(
@@ -25,3 +25,18 @@ export async function createSprint(
export async function getSprintsByProject(projectId: number) {
return await db.select().from(Sprint).where(eq(Sprint.projectId, projectId));
}
export async function hasOverlappingSprints(projectId: number, startDate: Date, endDate: Date) {
const overlapping = await db
.select({ id: Sprint.id })
.from(Sprint)
.where(
and(
eq(Sprint.projectId, projectId),
lte(Sprint.startDate, endDate),
gte(Sprint.endDate, startDate),
),
)
.limit(1);
return overlapping.length > 0;
}