Files
paperclip/server/src/services/goals.ts
Dotta f60c1001ec refactor: rename packages to @paperclipai and CLI binary to paperclipai
Rename all workspace packages from @paperclip/* to @paperclipai/* and
the CLI binary from `paperclip` to `paperclipai` in preparation for
npm publishing. Bump CLI version to 0.1.0 and add package metadata
(description, keywords, license, repository, files). Update all
imports, documentation, user-facing messages, and tests accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 08:45:26 -06:00

39 lines
1.0 KiB
TypeScript

import { eq } from "drizzle-orm";
import type { Db } from "@paperclipai/db";
import { goals } from "@paperclipai/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),
};
}