Load rule templates from API

This commit is contained in:
adilallo
2026-04-12 21:56:34 -06:00
parent cae4df261e
commit a39b4aa04b
17 changed files with 698 additions and 429 deletions
+30
View File
@@ -0,0 +1,30 @@
import type { RuleTemplateDto } from "../create/fetchTemplates";
import { prisma } from "./db";
import { isDatabaseConfigured } from "./env";
/**
* Curated templates for public list UIs (same query as GET /api/templates).
* Returns [] when the database is not configured or on query failure.
*/
export async function listRuleTemplatesFromDb(): Promise<RuleTemplateDto[]> {
if (!isDatabaseConfigured()) {
return [];
}
try {
return await prisma.ruleTemplate.findMany({
orderBy: [{ featured: "desc" }, { sortOrder: "asc" }, { title: "asc" }],
select: {
id: true,
slug: true,
title: true,
category: true,
description: true,
body: true,
sortOrder: true,
featured: true,
},
});
} catch {
return [];
}
}