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) => db .insert(goals) .values({ ...data, companyId }) .returning() .then((rows) => rows[0]), update: (id: string, data: Partial) => 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), }; }