feat: health check and stats endpoints (#290)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user