import type { User, Note } from "@prisma/client"; import { prisma } from "~/db.server"; export type { Note } from "@prisma/client"; export function getNote({ id, userId, }: Pick & { userId: User["id"]; }) { return prisma.note.findFirst({ where: { id, userId }, }); } export function getNoteListItems({ userId }: { userId: User["id"] }) { return prisma.note.findMany({ where: { userId }, select: { id: true, title: true }, orderBy: { updatedAt: "desc" }, }); } export function createNote({ body, title, userId, }: Pick & { userId: User["id"]; }) { return prisma.note.create({ data: { title, body, user: { connect: { id: userId, }, }, }, }); } export function deleteNote({ id, userId, }: Pick & { userId: User["id"] }) { return prisma.note.deleteMany({ where: { id, userId }, }); }