2026-02-16 13:31:58 -06:00
|
|
|
import { eq } from "drizzle-orm";
|
|
|
|
|
import type { Db } from "@paperclip/db";
|
|
|
|
|
import { goals } from "@paperclip/db";
|
|
|
|
|
|
|
|
|
|
export function goalService(db: Db) {
|
|
|
|
|
return {
|
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
|
|
|
list: (companyId: string) => db.select().from(goals).where(eq(goals.companyId, companyId)),
|
2026-02-16 13:31:58 -06:00
|
|
|
|
|
|
|
|
getById: (id: string) =>
|
|
|
|
|
db
|
|
|
|
|
.select()
|
|
|
|
|
.from(goals)
|
|
|
|
|
.where(eq(goals.id, id))
|
|
|
|
|
.then((rows) => rows[0] ?? null),
|
|
|
|
|
|
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
|
|
|
create: (companyId: string, data: Omit<typeof goals.$inferInsert, "companyId">) =>
|
2026-02-16 13:31:58 -06:00
|
|
|
db
|
|
|
|
|
.insert(goals)
|
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
|
|
|
.values({ ...data, companyId })
|
2026-02-16 13:31:58 -06:00
|
|
|
.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),
|
|
|
|
|
};
|
|
|
|
|
}
|