import { Injectable } from '@nestjs/common'; import { DataSource } from 'typeorm'; import { TenantAwareRepository } from '@it0/database'; import { AgentSession } from '../../domain/entities/agent-session.entity'; @Injectable() export class SessionRepository extends TenantAwareRepository { constructor(dataSource: DataSource) { super(dataSource, AgentSession); } async findByTenant(tenantId: string): Promise { return this.withRepository((repo) => repo.find({ where: { tenantId } as any }), ); } async findByStatus(status: string): Promise { return this.withRepository((repo) => repo.find({ where: { status } as any }), ); } async findByInstanceId(tenantId: string, agentInstanceId: string): Promise { return this.withRepository((repo) => repo.find({ where: { tenantId, agentInstanceId } as any, order: { updatedAt: 'DESC' }, }), ); } }