adds deleting

This commit is contained in:
2026-02-14 01:10:27 -08:00
parent 6f6dd434af
commit bec25aa943
4 changed files with 165 additions and 5 deletions

View File

@@ -50,7 +50,7 @@ async function storeNonAssistantMessages(chatId: string, messages: IncomingChatM
}
export async function registerRoutes(app: FastifyInstance) {
app.get("/health", async () => ({ ok: true }));
app.get("/health", { logLevel: "silent" }, async () => ({ ok: true }));
app.get("/v1/auth/session", async (req) => {
requireAdmin(req);
@@ -75,6 +75,23 @@ export async function registerRoutes(app: FastifyInstance) {
return { chat };
});
app.delete("/v1/chats/:chatId", async (req) => {
requireAdmin(req);
const Params = z.object({ chatId: z.string() });
const { chatId } = Params.parse(req.params);
req.log.info({ chatId }, "delete chat requested");
const result = await prisma.chat.deleteMany({ where: { id: chatId } });
if (result.count === 0) {
req.log.warn({ chatId }, "delete chat target not found");
return app.httpErrors.notFound("chat not found");
}
req.log.info({ chatId }, "chat deleted");
return { deleted: true };
});
app.get("/v1/searches", async (req) => {
requireAdmin(req);
const searches = await prisma.search.findMany({
@@ -101,6 +118,22 @@ export async function registerRoutes(app: FastifyInstance) {
return { search };
});
app.delete("/v1/searches/:searchId", async (req) => {
requireAdmin(req);
const Params = z.object({ searchId: z.string() });
const { searchId } = Params.parse(req.params);
req.log.info({ searchId }, "delete search requested");
const result = await prisma.search.deleteMany({ where: { id: searchId } });
if (result.count === 0) {
req.log.warn({ searchId }, "delete search target not found");
return app.httpErrors.notFound("search not found");
}
req.log.info({ searchId }, "search deleted");
return { deleted: true };
});
app.get("/v1/searches/:searchId", async (req) => {
requireAdmin(req);
const Params = z.object({ searchId: z.string() });