mirror of
https://github.com/paperclipai/paperclip
synced 2026-03-25 11:21:48 +00:00
Express server with CRUD routes for agents, goals, issues, projects, and activity log. Includes validation middleware, structured error handling, request logging, and health check endpoint with tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { eq, and, desc } from "drizzle-orm";
|
|
import type { Db } from "@paperclip/db";
|
|
import { activityLog } from "@paperclip/db";
|
|
|
|
export interface ActivityFilters {
|
|
agentId?: string;
|
|
entityType?: string;
|
|
entityId?: string;
|
|
}
|
|
|
|
export function activityService(db: Db) {
|
|
return {
|
|
list: (filters?: ActivityFilters) => {
|
|
const conditions = [];
|
|
|
|
if (filters?.agentId) {
|
|
conditions.push(eq(activityLog.agentId, filters.agentId));
|
|
}
|
|
if (filters?.entityType) {
|
|
conditions.push(eq(activityLog.entityType, filters.entityType));
|
|
}
|
|
if (filters?.entityId) {
|
|
conditions.push(eq(activityLog.entityId, filters.entityId));
|
|
}
|
|
|
|
const query = db.select().from(activityLog);
|
|
|
|
if (conditions.length > 0) {
|
|
return query.where(and(...conditions)).orderBy(desc(activityLog.createdAt));
|
|
}
|
|
|
|
return query.orderBy(desc(activityLog.createdAt));
|
|
},
|
|
|
|
create: (data: typeof activityLog.$inferInsert) =>
|
|
db
|
|
.insert(activityLog)
|
|
.values(data)
|
|
.returning()
|
|
.then((rows) => rows[0]),
|
|
};
|
|
}
|