mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 10:33:01 +00:00
only show status remove warning if it is being used
This commit is contained in:
@@ -71,6 +71,25 @@ export async function getIssueByNumber(projectId: number, number: number) {
|
||||
return issue;
|
||||
}
|
||||
|
||||
export async function getIssueStatusCountByOrganisation(organisationId: number, status: string) {
|
||||
const { Project } = await import("@issue/shared");
|
||||
|
||||
const projects = await db
|
||||
.select({ id: Project.id })
|
||||
.from(Project)
|
||||
.where(eq(Project.organisationId, organisationId));
|
||||
const projectIds = projects.map((p) => p.id);
|
||||
|
||||
if (projectIds.length === 0) return { count: 0 };
|
||||
|
||||
const [result] = await db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(Issue)
|
||||
.where(and(eq(Issue.status, status), inArray(Issue.projectId, projectIds)));
|
||||
|
||||
return { count: result?.count ?? 0 };
|
||||
}
|
||||
|
||||
export async function replaceIssueStatus(organisationId: number, oldStatus: string, newStatus: string) {
|
||||
const { Project } = await import("@issue/shared");
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ const main = async () => {
|
||||
|
||||
"/issues/by-project": withCors(withAuth(routes.issuesByProject)),
|
||||
"/issues/replace-status": withCors(withAuth(withCSRF(routes.issuesReplaceStatus))),
|
||||
"/issues/status-count": withCors(withAuth(routes.issuesStatusCount)),
|
||||
"/issues/all": withCors(withAuth(routes.issues)),
|
||||
|
||||
"/organisation/create": withCors(withAuth(withCSRF(routes.organisationCreate))),
|
||||
|
||||
@@ -8,6 +8,7 @@ import issueUpdate from "./issue/update";
|
||||
import issues from "./issues/all";
|
||||
import issuesByProject from "./issues/by-project";
|
||||
import issuesReplaceStatus from "./issues/replace-status";
|
||||
import issuesStatusCount from "./issues/status-count";
|
||||
import organisationAddMember from "./organisation/add-member";
|
||||
import organisationById from "./organisation/by-id";
|
||||
import organisationsByUser from "./organisation/by-user";
|
||||
@@ -50,6 +51,7 @@ export const routes = {
|
||||
issuesByProject,
|
||||
issues,
|
||||
issuesReplaceStatus,
|
||||
issuesStatusCount,
|
||||
|
||||
organisationCreate,
|
||||
organisationById,
|
||||
|
||||
31
packages/backend/src/routes/issues/status-count.ts
Normal file
31
packages/backend/src/routes/issues/status-count.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { AuthedRequest } from "../../auth/middleware";
|
||||
import { getIssueStatusCountByOrganisation, getOrganisationMemberRole } from "../../db/queries";
|
||||
|
||||
// /issues/status-count?organisationId=1&status=TODO
|
||||
export default async function issuesStatusCount(req: AuthedRequest) {
|
||||
const url = new URL(req.url);
|
||||
const organisationIdParam = url.searchParams.get("organisationId");
|
||||
const status = url.searchParams.get("status");
|
||||
|
||||
if (!organisationIdParam) {
|
||||
return new Response("missing organisationId", { status: 400 });
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
return new Response("missing status", { status: 400 });
|
||||
}
|
||||
|
||||
const organisationId = Number(organisationIdParam);
|
||||
if (!Number.isInteger(organisationId)) {
|
||||
return new Response("organisationId must be an integer", { status: 400 });
|
||||
}
|
||||
|
||||
const membership = await getOrganisationMemberRole(organisationId, req.userId);
|
||||
if (!membership) {
|
||||
return new Response("not a member of this organisation", { status: 403 });
|
||||
}
|
||||
|
||||
const result = await getIssueStatusCountByOrganisation(organisationId, status);
|
||||
|
||||
return Response.json(result);
|
||||
}
|
||||
Reference in New Issue
Block a user