Files
paperclip/server/src/services/goals.ts
Forgotten abadd469bc Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00

39 lines
1.0 KiB
TypeScript

import { eq } from "drizzle-orm";
import type { Db } from "@paperclip/db";
import { goals } from "@paperclip/db";
export function goalService(db: Db) {
return {
list: (companyId: string) => db.select().from(goals).where(eq(goals.companyId, companyId)),
getById: (id: string) =>
db
.select()
.from(goals)
.where(eq(goals.id, id))
.then((rows) => rows[0] ?? null),
create: (companyId: string, data: Omit<typeof goals.$inferInsert, "companyId">) =>
db
.insert(goals)
.values({ ...data, companyId })
.returning()
.then((rows) => rows[0]),
update: (id: string, data: Partial<typeof goals.$inferInsert>) =>
db
.update(goals)
.set({ ...data, updatedAt: new Date() })
.where(eq(goals.id, id))
.returning()
.then((rows) => rows[0] ?? null),
remove: (id: string) =>
db
.delete(goals)
.where(eq(goals.id, id))
.returning()
.then((rows) => rows[0] ?? null),
};
}