Spaces:
Runtime error
Runtime error
| import type { Prisma } from "@prisma/client"; | |
| import { requireCaseByIdForOwner } from "@/server/cases/service"; | |
| import { db } from "@/server/db"; | |
| import type { CaseChatQuestionInput } from "@/server/validation/case"; | |
| export async function listCaseChatTurnsForOwner( | |
| ownerId: string, | |
| customerId: string, | |
| caseId: string, | |
| ) { | |
| await requireCaseByIdForOwner(ownerId, customerId, caseId); | |
| return db.caseChatTurn.findMany({ | |
| where: { | |
| ownerId, | |
| customerId, | |
| caseId, | |
| }, | |
| orderBy: { | |
| createdAt: "asc", | |
| }, | |
| }); | |
| } | |
| export async function listRecentCaseChatTurnsForOwner( | |
| ownerId: string, | |
| customerId: string, | |
| caseId: string, | |
| take = 8, | |
| ) { | |
| await requireCaseByIdForOwner(ownerId, customerId, caseId); | |
| return db.caseChatTurn.findMany({ | |
| where: { | |
| ownerId, | |
| customerId, | |
| caseId, | |
| }, | |
| orderBy: { | |
| createdAt: "desc", | |
| }, | |
| take, | |
| }); | |
| } | |
| export async function createCaseChatTurnForOwner( | |
| ownerId: string, | |
| customerId: string, | |
| caseId: string, | |
| input: CaseChatQuestionInput & { | |
| answer: string; | |
| sources: unknown; | |
| }, | |
| ) { | |
| await requireCaseByIdForOwner(ownerId, customerId, caseId); | |
| return db.caseChatTurn.create({ | |
| data: { | |
| ownerId, | |
| customerId, | |
| caseId, | |
| question: input.question.trim(), | |
| answer: input.answer, | |
| sources: input.sources as Prisma.InputJsonValue, | |
| }, | |
| }); | |
| } | |