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>
39 lines
965 B
TypeScript
39 lines
965 B
TypeScript
import { eq } from "drizzle-orm";
|
|
import type { Db } from "@paperclip/db";
|
|
import { projects } from "@paperclip/db";
|
|
|
|
export function projectService(db: Db) {
|
|
return {
|
|
list: () => db.select().from(projects),
|
|
|
|
getById: (id: string) =>
|
|
db
|
|
.select()
|
|
.from(projects)
|
|
.where(eq(projects.id, id))
|
|
.then((rows) => rows[0] ?? null),
|
|
|
|
create: (data: typeof projects.$inferInsert) =>
|
|
db
|
|
.insert(projects)
|
|
.values(data)
|
|
.returning()
|
|
.then((rows) => rows[0]),
|
|
|
|
update: (id: string, data: Partial<typeof projects.$inferInsert>) =>
|
|
db
|
|
.update(projects)
|
|
.set({ ...data, updatedAt: new Date() })
|
|
.where(eq(projects.id, id))
|
|
.returning()
|
|
.then((rows) => rows[0] ?? null),
|
|
|
|
remove: (id: string) =>
|
|
db
|
|
.delete(projects)
|
|
.where(eq(projects.id, id))
|
|
.returning()
|
|
.then((rows) => rows[0] ?? null),
|
|
};
|
|
}
|