Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,154 @@
|
||||
import { KnowledgeBase } from "@toolctrl/db/prisma-browser";
|
||||
import { clearCacheKey } from "~/utils/cache.server";
|
||||
import { db, dbRead } from "~/utils/db.server";
|
||||
|
||||
export type KnowledgeBaseWithDetails = KnowledgeBase & {
|
||||
_count: {
|
||||
categories: number;
|
||||
articles: number;
|
||||
views: number;
|
||||
};
|
||||
};
|
||||
|
||||
const include = {
|
||||
_count: {
|
||||
select: { categories: true, articles: true, views: true },
|
||||
},
|
||||
};
|
||||
|
||||
function knowledgeBaseOwnerKey(tenantId?: string | null) {
|
||||
return tenantId ?? "global";
|
||||
}
|
||||
|
||||
export async function getAllKnowledgeBases({ enabled, tenantId }: { enabled?: boolean; tenantId?: string | null } = {}): Promise<KnowledgeBaseWithDetails[]> {
|
||||
// Listing for KB management UI and public KB discovery — read-only.
|
||||
return await dbRead.knowledgeBase.findMany({
|
||||
where: { enabled, ownerKey: knowledgeBaseOwnerKey(tenantId) },
|
||||
include,
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllKnowledgeBaseNames({ tenantId }: { tenantId?: string | null } = {}): Promise<{ id: string; title: string }[]> {
|
||||
// Simple enumeration — read-only.
|
||||
return await dbRead.knowledgeBase.findMany({
|
||||
where: { ownerKey: knowledgeBaseOwnerKey(tenantId) },
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getKnowledgeBaseById(id: string): Promise<KnowledgeBaseWithDetails | null> {
|
||||
// Read-only lookup.
|
||||
return await dbRead.knowledgeBase.findUnique({
|
||||
where: { id },
|
||||
include,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getKnowledgeBaseBySlug(slug: string, { tenantId }: { tenantId?: string | null } = {}): Promise<KnowledgeBaseWithDetails | null> {
|
||||
// Public route lookup, read-only.
|
||||
return await dbRead.knowledgeBase.findUnique({
|
||||
where: { ownerKey_slug: { ownerKey: knowledgeBaseOwnerKey(tenantId), slug } },
|
||||
include,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createKnowledgeBase(data: {
|
||||
basePath: string;
|
||||
slug: string;
|
||||
tenantId?: string | null;
|
||||
title: string;
|
||||
description: string;
|
||||
defaultLanguage: string;
|
||||
layout: string;
|
||||
color: number;
|
||||
enabled: boolean;
|
||||
languages: string;
|
||||
links: string;
|
||||
logo: string;
|
||||
seoImage: string;
|
||||
}) {
|
||||
return await db.knowledgeBase.create({
|
||||
data: {
|
||||
basePath: data.basePath,
|
||||
slug: data.slug,
|
||||
tenantId: data.tenantId ?? null,
|
||||
ownerKey: knowledgeBaseOwnerKey(data.tenantId),
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
defaultLanguage: data.defaultLanguage,
|
||||
layout: data.layout,
|
||||
color: data.color,
|
||||
enabled: data.enabled,
|
||||
languages: data.languages,
|
||||
links: data.links,
|
||||
logo: data.logo,
|
||||
seoImage: data.seoImage,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateKnowledgeBase(
|
||||
id: string,
|
||||
data: {
|
||||
basePath?: string;
|
||||
slug?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
defaultLanguage?: string;
|
||||
layout?: string;
|
||||
color?: number;
|
||||
enabled?: boolean;
|
||||
languages?: string;
|
||||
links?: string;
|
||||
logo?: string;
|
||||
seoImage?: string;
|
||||
}
|
||||
) {
|
||||
return await db.knowledgeBase
|
||||
.update({
|
||||
where: { id },
|
||||
data: {
|
||||
basePath: data.basePath,
|
||||
slug: data.slug,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
defaultLanguage: data.defaultLanguage,
|
||||
layout: data.layout,
|
||||
color: data.color,
|
||||
enabled: data.enabled,
|
||||
languages: data.languages,
|
||||
links: data.links,
|
||||
logo: data.logo,
|
||||
seoImage: data.seoImage,
|
||||
},
|
||||
})
|
||||
.then((item) => {
|
||||
clearCacheKey(`kb:${item.slug}`);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteKnowledgeBase(id: string) {
|
||||
return await db.knowledgeBase
|
||||
.delete({
|
||||
where: { id },
|
||||
})
|
||||
.then((item) => {
|
||||
clearCacheKey(`kb:${item.slug}`);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export async function countKnowledgeBases() {
|
||||
// Dashboard count — read-only.
|
||||
return await dbRead.knowledgeBase.count();
|
||||
}
|
||||
Reference in new issue
Block a user