import { Injectable } from '@nestjs/common'; import { PrismaService } from '../../infrastructure/database/prisma.service'; @Injectable() export class KnowledgeBaseRepository { constructor(private readonly prisma: PrismaService) {} async create(userId: string, dto: { title: string; description?: string }) { return this.prisma.knowledgeBase.create({ data: { userId, title: dto.title, description: dto.description ?? '', status: 'active', itemCount: 0, }, }); } async findById(id: string) { return this.prisma.knowledgeBase.findUnique({ where: { id } }); } async findAllByUserId(userId: string) { return this.prisma.knowledgeBase.findMany({ where: { userId, deletedAt: null }, orderBy: { updatedAt: 'desc' }, }); } async countByUserId(userId: string) { return this.prisma.knowledgeBase.count({ where: { userId, deletedAt: null }, }); } async update(id: string, dto: { title?: string; description?: string }) { return this.prisma.knowledgeBase.update({ where: { id }, data: dto, }); } async softDelete(id: string) { await this.prisma.knowledgeBase.update({ where: { id }, data: { deletedAt: new Date() }, }); return true; } }