feat: health check and stats endpoints (#290)

This commit is contained in:
Henry
2025-12-18 08:08:30 +00:00
committed by GitHub
parent 57186b6b4d
commit cca8a9d424
22 changed files with 447 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
import {
and,
asc,
count,
desc,
eq,
gte,
@@ -29,6 +30,15 @@ import {
} from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(boards)
.where(isNull(boards.deletedAt));
return result[0]?.count ?? 0;
};
export const getAllByWorkspaceId = (
db: dbClient,
workspaceId: number,

View File

@@ -1,4 +1,14 @@
import { and, asc, desc, eq, gt, inArray, isNull, lt, sql } from "drizzle-orm";
import {
and,
asc,
count,
desc,
eq,
gt,
inArray,
isNull,
sql,
} from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import {
@@ -9,13 +19,21 @@ import {
cardToWorkspaceMembers,
checklistItems,
checklists,
comments,
labels,
lists,
workspaceMembers,
} from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(cards)
.where(isNull(cards.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
cardInput: {

View File

@@ -1,10 +1,16 @@
import { and, asc, eq, gt, inArray, isNull, or } from "drizzle-orm";
import { and, asc, count, eq, gt, inArray, isNull, or } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import type { ActivityType } from "@kan/db/schema";
import { cardActivities, comments } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db.select({ count: count() }).from(cardActivities);
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
activityInput: {

View File

@@ -1,9 +1,18 @@
import { and, eq, isNull } from "drizzle-orm";
import { and, count, eq, isNull } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { cardAttachments } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(cardAttachments)
.where(isNull(cardAttachments.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
attachmentInput: {

View File

@@ -1,9 +1,18 @@
import { eq } from "drizzle-orm";
import { count, eq, isNull } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { comments } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(comments)
.where(isNull(comments.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
commentInput: {

View File

@@ -1,9 +1,24 @@
import { and, desc, eq, isNull, sql } from "drizzle-orm";
import { and, count, desc, eq, isNull, sql } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { checklistItems, checklists } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(checklists)
.where(isNull(checklists.deletedAt));
return result[0]?.count ?? 0;
};
export const getCountItems = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(checklistItems)
.where(isNull(checklistItems.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
@@ -357,7 +372,10 @@ export const reorderItem = async (
index: true,
checklistId: true,
},
where: and(eq(checklistItems.id, args.itemId), isNull(checklistItems.deletedAt)),
where: and(
eq(checklistItems.id, args.itemId),
isNull(checklistItems.deletedAt),
),
});
if (!item) {
@@ -374,7 +392,10 @@ export const reorderItem = async (
title: true,
completed: true,
},
where: and(eq(checklistItems.id, args.itemId), isNull(checklistItems.deletedAt)),
where: and(
eq(checklistItems.id, args.itemId),
isNull(checklistItems.deletedAt),
),
});
if (!unchanged) {
@@ -418,7 +439,6 @@ export const reorderItem = async (
throw new Error(`Failed to update checklist item with ID ${args.itemId}`);
}
return updated;
});
}
return updated;
});
};

View File

@@ -1,9 +1,15 @@
import { eq } from "drizzle-orm";
import { count, eq } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { imports } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db.select({ count: count() }).from(imports);
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
importInput: { source: string; createdBy: string },

View File

@@ -1,9 +1,18 @@
import { and, eq, gt } from "drizzle-orm";
import { and, count, eq } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { workspaceInviteLinks } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getActiveCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(workspaceInviteLinks)
.where(eq(workspaceInviteLinks.status, "active"));
return result[0]?.count ?? 0;
};
export const createInviteLink = async (
db: dbClient,
args: {

View File

@@ -1,9 +1,18 @@
import { and, eq, inArray, isNull } from "drizzle-orm";
import { and, count, eq, inArray, isNull } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { cardsToLabels, labels } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(labels)
.where(isNull(labels.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
labelInput: {

View File

@@ -1,9 +1,18 @@
import { and, desc, eq, gt, isNull, sql } from "drizzle-orm";
import { and, count, desc, eq, gt, isNull, sql } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { lists } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(lists)
.where(isNull(lists.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
listInput: {

View File

@@ -1,10 +1,24 @@
import { and, eq, isNull } from "drizzle-orm";
import { and, count, eq, isNull } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import type { MemberRole, MemberStatus } from "@kan/db/schema";
import { workspaceMembers } from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getActiveCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(workspaceMembers)
.where(
and(
isNull(workspaceMembers.deletedAt),
eq(workspaceMembers.status, "active"),
),
);
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
memberInput: {

View File

@@ -1,9 +1,15 @@
import { desc, eq } from "drizzle-orm";
import { count, desc, eq } from "drizzle-orm";
import { v4 as uuidv4 } from "uuid";
import type { dbClient } from "@kan/db/client";
import { apikey, users } from "@kan/db/schema";
export const getCount = async (db: dbClient) => {
const result = await db.select({ count: count() }).from(users);
return result[0]?.count ?? 0;
};
export const getById = async (db: dbClient, userId: string) => {
return await db.query.users.findFirst({
columns: {

View File

@@ -1,4 +1,14 @@
import { and, desc, eq, ilike, inArray, isNull, or, sql } from "drizzle-orm";
import {
and,
count,
desc,
eq,
ilike,
inArray,
isNull,
or,
sql,
} from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import {
@@ -10,6 +20,15 @@ import {
} from "@kan/db/schema";
import { generateUID } from "@kan/shared/utils";
export const getCount = async (db: dbClient) => {
const result = await db
.select({ count: count() })
.from(workspaces)
.where(isNull(workspaces.deletedAt));
return result[0]?.count ?? 0;
};
export const create = async (
db: dbClient,
workspaceInput: {