import { Injectable } from '@nestjs/common'; import { PrismaService } from '../../infrastructure/database/prisma.service'; @Injectable() export class KnowledgeItemsRepository { constructor(private readonly prisma: PrismaService) {} async create(userId: string, knowledgeBaseId: string, dto: { title?: string; content?: string; parentId?: string; itemType?: string; orderIndex?: number; }) { return this.prisma.knowledgeItem.create({ data: { userId, knowledgeBaseId, title: dto.title ?? '', content: dto.content ?? '', parentId: dto.parentId ?? null, itemType: dto.itemType ?? 'lesson', orderIndex: dto.orderIndex ?? 0, }, }); } async findById(id: string) { return this.prisma.knowledgeItem.findUnique({ where: { id } }); } async findByKnowledgeBaseId(knowledgeBaseId: string) { return this.prisma.knowledgeItem.findMany({ where: { knowledgeBaseId, deletedAt: null }, orderBy: { orderIndex: 'asc' }, }); } async update(id: string, dto: Record) { return this.prisma.knowledgeItem.update({ where: { id }, data: dto, }); } }